use axum::{
    Router,
    routing::{get, post},
};
use axum_extra::routing::RouterExt as _;

use crate::app::App;

mod add_field_handler;
mod add_portal_handler;
mod form_handler;
mod get_data_handler;
mod insert_handler;
mod portal_handler;
mod portal_settings_handler;
mod set_filter_handler;
mod settings_handler;
mod settings_invite_handler;
mod update_form_transitions_handler;
mod update_portal_name_handler;
mod update_prompts_handler;
mod update_rel_name_handler;
mod update_value_handler;

pub(super) fn new_router() -> Router<App> {
    Router::<App>::new()
        .route_with_tsr("/settings/", get(settings_handler::get))
        .route("/settings/invite", post(settings_invite_handler::post))
        .route("/settings/update-name", post(update_rel_name_handler::post))
        .route("/add-portal", post(add_portal_handler::post))
        .route_with_tsr("/p/{portal_id}/", get(portal_handler::get))
        .route_with_tsr("/p/{portal_id}/get-data/", get(get_data_handler::get))
        .route_with_tsr(
            "/p/{portal_id}/settings/",
            get(portal_settings_handler::get),
        )
        .route(
            "/p/{portal_id}/settings/update-name",
            post(update_portal_name_handler::post),
        )
        .route("/p/{portal_id}/add-field", post(add_field_handler::post))
        .route("/p/{portal_id}/insert", post(insert_handler::post))
        .route(
            "/p/{portal_id}/update-value",
            post(update_value_handler::post),
        )
        .route("/p/{portal_id}/set-filter", post(set_filter_handler::post))
        .route_with_tsr("/p/{portal_id}/form/", get(form_handler::get))
        .route(
            "/p/{portal_id}/form/update-prompts",
            post(update_prompts_handler::post),
        )
        .route(
            "/p/{portal_id}/form/update-form-transitions",
            post(update_form_transitions_handler::post),
        )
}
