pub mod merge;
pub mod pull_request;
pub mod review;
pub mod review_comment;
pub mod review_request;

use actix_web::web;

#[derive(serde::Deserialize, utoipa::IntoParams)]
pub struct ListQuery {
    pub status: Option<String>,
    pub page: Option<i64>,
    pub per_page: Option<i64>,
}

pub fn init_pull_request_routes(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/repo_pr/{namespace}/{repo}/pulls")
            .route("", web::get().to(pull_request::pull_request_list))
            .route("", web::post().to(pull_request::pull_request_create))
            .route(
                "/summary",
                web::get().to(pull_request::pull_request_summary),
            )
            .route("/{number}", web::get().to(pull_request::pull_request_get))
            .route(
                "/{number}",
                web::patch().to(pull_request::pull_request_update),
            )
            .route(
                "/{number}",
                web::delete().to(pull_request::pull_request_delete),
            )
            .route(
                "/{number}/close",
                web::post().to(pull_request::pull_request_close),
            )
            .route(
                "/{number}/reopen",
                web::post().to(pull_request::pull_request_reopen),
            )
            // reviews (from pull_request module)
            .route(
                "/{pr_number}/reviews",
                web::get().to(pull_request::review_list),
            )
            .route(
                "/{pr_number}/reviews",
                web::post().to(pull_request::review_submit),
            )
            .route(
                "/{pr_number}/reviews",
                web::patch().to(pull_request::review_update),
            )
            .route(
                "/{pr_number}/reviews/{reviewer_id}",
                web::delete().to(pull_request::review_delete),
            )
            // review comments (from pull_request module)
            .route(
                "/{pr_number}/comments",
                web::get().to(pull_request::review_comment_list),
            )
            .route(
                "/{pr_number}/comments",
                web::post().to(pull_request::review_comment_create),
            )
            .route(
                "/{pr_number}/comments/{comment_id}",
                web::patch().to(pull_request::review_comment_update),
            )
            .route(
                "/{pr_number}/comments/{comment_id}",
                web::delete().to(pull_request::review_comment_delete),
            )
            .route(
                "/{pr_number}/comments/{comment_id}/resolve",
                web::put().to(review_comment::review_comment_resolve),
            )
            .route(
                "/{pr_number}/comments/{comment_id}/resolve",
                web::delete().to(review_comment::review_comment_unresolve),
            )
            .route(
                "/{pr_number}/comments/{comment_id}/replies",
                web::post().to(review_comment::review_comment_reply),
            )
            .route(
                "/{pr_number}/commits",
                web::get().to(pull_request::pr_commits_list),
            )
            // merge
            .route(
                "/{pr_number}/merge",
                web::get().to(pull_request::merge_analysis),
            )
            .route(
                "/{pr_number}/conflicts",
                web::get().to(pull_request::merge_conflict_check),
            )
            .route(
                "/{pr_number}/merge",
                web::post().to(pull_request::merge_execute),
            )
            .route(
                "/{pr_number}/merge/abort",
                web::post().to(pull_request::merge_abort),
            )
            .route(
                "/{pr_number}/merge/in_progress",
                web::get().to(pull_request::merge_is_in_progress),
            )
            // side-by-side diff
            .route(
                "/{pr_number}/diff/side-by-side",
                web::get().to(pull_request::pr_diff_side_by_side),
            )
            // review requests
            .route(
                "/{pr_number}/review-requests",
                web::get().to(review_request::review_request_list),
            )
            .route(
                "/{pr_number}/review-requests",
                web::post().to(review_request::review_request_create),
            )
            .route(
                "/{pr_number}/review-requests/{reviewer}",
                web::delete().to(review_request::review_request_delete),
            )
            .route(
                "/{pr_number}/review-requests/{reviewer}/dismiss",
                web::post().to(review_request::review_request_dismiss),
            ),
    );
}
