pub mod captcha;
pub mod email;
pub mod login;
pub mod logout;
pub mod me;
pub mod register;
pub mod reset_pass;
pub mod rsa;
pub mod totp;

use actix_web::{web, web::ServiceConfig};

pub fn configure(cfg: &mut ServiceConfig) {
    cfg.service(
        web::scope("/auth")
            .service(
                web::resource("/captcha")
                    .route(web::get().to(captcha::captcha)),
            )
            .service(
                web::resource("/login").route(web::post().to(login::login)),
            )
            .service(
                web::resource("/logout").route(web::post().to(logout::logout)),
            )
            .service(web::resource("/me").route(web::get().to(me::me)))
            .service(
                web::resource("/register")
                    .route(web::post().to(register::register)),
            )
            .service(
                web::scope("/reset-password")
                    .service(web::resource("/request").route(
                        web::post().to(reset_pass::reset_password_request),
                    ))
                    .service(web::resource("/verify").route(
                        web::post().to(reset_pass::reset_password_verify),
                    )),
            )
            .service(
                web::resource("/public-key").route(web::get().to(rsa::rsa)),
            )
            .service(
                web::scope("/2fa")
                    .service(
                        web::resource("/enable")
                            .route(web::post().to(totp::enable_2fa)),
                    )
                    .service(
                        web::resource("/verify")
                            .route(web::post().to(totp::verify_2fa)),
                    )
                    .service(
                        web::resource("")
                            .route(web::get().to(totp::status_2fa))
                            .route(web::delete().to(totp::disable_2fa)),
                    )
                    .service(
                        web::resource("/backup-codes").route(
                            web::post().to(totp::regenerate_backup_codes),
                        ),
                    ),
            )
            .service(
                web::scope("/email")
                    .service(
                        web::resource("")
                            .route(web::get().to(email::get_email))
                            .route(web::put().to(email::email_change_request)),
                    )
                    .service(
                        web::resource("/verify")
                            .route(web::post().to(email::email_verify)),
                    ),
            ),
    );
}
