mod bulk;
pub(crate) mod case_actions;
mod debug;
mod events;
mod health;
mod login;
mod magic;
mod oneliner_override;
mod oneliners;
mod upload;
pub(crate) mod user_web;
pub(crate) mod web;

use axum::Router;
use axum::routing::{get, post, put};

use crate::AppState;

pub fn api_router() -> Router<AppState> {
    Router::new()
        .route("/api/health", get(health::handle_health))
        .route("/api/debug/whoami", get(debug::handle_whoami))
        .route("/api/upload", post(upload::handle_upload))
        .route("/api/oneliners", get(oneliners::handle_oneliners))
        .route(
            "/api/cases/{case_id}/oneliner",
            put(oneliner_override::handle_put_oneliner),
        )
        .route("/api/auth/magic-link", post(magic::handle_create))
        .route("/web/magic", get(magic::handle_consume))
        .route(
            "/web/login",
            get(login::handle_login_page).post(login::handle_login_submit),
        )
        .route("/web/logout", post(login::handle_logout))
        .route("/web/cases", get(user_web::handle_my_cases))
        .route("/web/cases/{case_id}", get(user_web::handle_case_page))
        .route(
            "/web/cases/{case_id}/recordings",
            get(user_web::handle_case_recordings),
        )
        .route(
            "/web/cases/{case_id}/recordings/delete",
            post(case_actions::handle_delete_recording),
        )
        .route(
            "/web/cases/{case_id}/analyze",
            post(case_actions::handle_analyze_case),
        )
        .route(
            "/web/cases/{case_id}/close",
            post(case_actions::handle_close_case),
        )
        .route(
            "/web/cases/{case_id}/reopen",
            post(case_actions::handle_reopen_case),
        )
        .route(
            "/web/cases/{case_id}/reset",
            post(case_actions::handle_reset_case),
        )
        .route(
            "/web/cases/{case_id}/oneliner",
            post(oneliner_override::handle_web_put_oneliner),
        )
        .route(
            "/web/cases/purge-closed",
            post(case_actions::handle_purge_closed),
        )
        .route("/web/cases/bulk", post(bulk::handle_bulk_action))
        .route(
            "/web/audio/{user}/{case_id}/{filename}",
            get(web::handle_audio),
        )
        .route("/web/events", get(events::handle_events))
}
