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 get_data_handler;
mod insert_handler;
mod portal_handler;
mod portal_settings_handler;
mod remove_field_handler;
mod set_filter_handler;
mod settings_handler;
mod update_field_handler;
mod update_field_ordinality_handler;
mod update_field_table_width_px_handler;
mod update_portal_name_handler;
mod update_rel_name_handler;
mod update_values_handler;

pub(super) fn new_router() -> Router<App> {
    Router::<App>::new()
        .route_with_tsr("/settings/", get(settings_handler::get))
        .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}/update-field",
            post(update_field_handler::post),
        )
        .route(
            "/p/{portal_id}/remove-field",
            post(remove_field_handler::post),
        )
        .route(
            "/p/{portal_id}/update-field-ordinality",
            post(update_field_ordinality_handler::post),
        )
        .route(
            "/p/{portal_id}/update-field-table-width-px",
            post(update_field_table_width_px_handler::post),
        )
        .route("/p/{portal_id}/insert", post(insert_handler::post))
        .route(
            "/p/{portal_id}/update-values",
            post(update_values_handler::post),
        )
        .route("/p/{portal_id}/set-filter", post(set_filter_handler::post))
}
