pub mod billing;
pub mod info;
pub mod init;
pub mod members;
pub mod projects;
pub mod settings;
pub mod stats;

use actix_web::web;

pub fn init_workspace_routes(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/workspaces")
            .route("", web::post().to(init::workspace_create))
            .route("/me", web::get().to(info::workspace_list))
            .route("/{slug}", web::get().to(info::workspace_info))
            // Billing
            .route(
                "/{slug}/billing",
                web::get().to(billing::workspace_billing_current),
            )
            .route(
                "/{slug}/billing/history",
                web::get().to(billing::workspace_billing_history),
            )
            .route(
                "/{slug}/billing/credits",
                web::post().to(billing::workspace_billing_add_credit),
            )
            // Projects
            .route(
                "/{slug}/projects",
                web::get().to(projects::workspace_projects),
            )
            // Stats
            .route("/{slug}/stats", web::get().to(stats::workspace_stats))
            // Settings
            .route("/{slug}", web::patch().to(settings::workspace_update))
            .route("/{slug}", web::delete().to(settings::workspace_delete))
            // Members
            .route("/{slug}/members", web::get().to(members::workspace_members))
            .route(
                "/{slug}/members/{user_id}",
                web::delete().to(members::workspace_remove_member),
            )
            .route(
                "/{slug}/members/role",
                web::patch().to(members::workspace_update_member_role),
            )
            // Invitations
            .route(
                "/me/invitations",
                web::get().to(members::workspace_my_invitations),
            )
            .route(
                "/invitations/accept",
                web::post().to(members::workspace_accept_invitation),
            )
            .route(
                "/invitations/accept-by-slug",
                web::post().to(members::workspace_accept_invitation_by_slug),
            )
            .route(
                "/{slug}/invitations",
                web::post().to(members::workspace_invite_member),
            )
            .route(
                "/{slug}/invitations",
                web::get().to(members::workspace_pending_invitations),
            )
            .route(
                "/{slug}/invitations/{user_id}",
                web::delete().to(members::workspace_cancel_invitation),
            ),
    );
}
