pub mod access_key;
pub mod chpc;
pub mod notification;
pub mod preferences;
pub mod profile;
pub mod projects;
pub mod repository;
pub mod ssh_key;
pub mod stars;
pub mod subscribe;
pub mod user_activity;
pub mod user_info;

use actix_web::web;

pub fn init_user_routes(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/users")
            .route("/me/profile", web::get().to(profile::get_my_profile))
            .route("/me/profile", web::patch().to(profile::update_my_profile))
            .route(
                "/me/preferences",
                web::get().to(preferences::get_preferences),
            )
            .route(
                "/me/preferences",
                web::patch().to(preferences::update_preferences),
            )
            .route("/me/keys", web::post().to(ssh_key::add_ssh_key))
            .route("/me/keys", web::get().to(ssh_key::list_ssh_keys))
            .route("/me/keys/{key_id}", web::get().to(ssh_key::get_ssh_key))
            .route(
                "/me/keys/{key_id}",
                web::patch().to(ssh_key::update_ssh_key),
            )
            .route(
                "/me/keys/{key_id}",
                web::delete().to(ssh_key::delete_ssh_key),
            )
            .route(
                "/me/access-keys",
                web::post().to(access_key::create_access_key),
            )
            .route(
                "/me/access-keys",
                web::get().to(access_key::list_access_keys),
            )
            .route(
                "/me/access-keys/{access_key_id}",
                web::delete().to(access_key::delete_access_key),
            )
            .route(
                "/me/notifications/preferences",
                web::get().to(notification::get_notification_preferences),
            )
            .route(
                "/me/notifications/preferences",
                web::patch().to(notification::update_notification_preferences),
            )
            .route(
                "/me/notifications/push/vapid-key",
                web::get().to(notification::get_vapid_public_key),
            )
            .route(
                "/me/notifications/push/subscription",
                web::delete().to(notification::unsubscribe_push),
            )
            .route(
                "/me/heatmap",
                web::get().to(chpc::get_my_contribution_heatmap),
            )
            .route(
                "/me/projects",
                web::get().to(projects::get_current_user_projects),
            )
            .route(
                "/me/repos",
                web::get().to(repository::get_current_user_repos),
            )
            // /users/{username}/...
            .route(
                "/{username}",
                web::get().to(profile::get_profile_by_username),
            )
            .route("/{username}/info", web::get().to(user_info::get_user_info))
            .route(
                "/{username}/heatmap",
                web::get().to(chpc::get_contribution_heatmap),
            )
            .route("/{username}/keys", web::get().to(ssh_key::list_ssh_keys))
            .route("/{username}/activity", web::get().to(user_activity::get_user_activity))
            .route("/{username}/stars", web::get().to(stars::get_user_stars))
            .route(
                "/{username}/keys/{key_id}",
                web::get().to(ssh_key::get_ssh_key),
            )
            .route(
                "/{username}/projects",
                web::get().to(projects::get_user_projects),
            )
            .route(
                "/{username}/repos",
                web::get().to(repository::get_user_repos),
            )
            .route(
                "/{username}/follow",
                web::post().to(subscribe::subscribe_target),
            )
            .route(
                "/{username}/follow",
                web::delete().to(subscribe::unsubscribe_target),
            )
            .route(
                "/{username}/follow",
                web::get().to(subscribe::is_subscribed_to_target),
            )
            .route(
                "/{username}/followers",
                web::get().to(subscribe::get_subscribers),
            )
            .route(
                "/{username}/following/count",
                web::get().to(subscribe::get_subscription_count),
            )
            .route(
                "/{username}/following",
                web::get().to(subscribe::get_following_list),
            )
            .route(
                "/{username}/followers/count",
                web::get().to(subscribe::get_subscriber_count),
            ),
    );
}
