mod note;
mod streaming;
mod user;

use crate::api_v1::note::handle_note;
use crate::api_v1::streaming::handle_streaming;
use crate::api_v1::user::{
    handle_follow_requests_self, handle_followers, handle_followers_self, handle_following,
    handle_following_self, handle_notifications, handle_user_by_id_many, handle_user_info,
    handle_user_info_by_acct, handle_user_info_self,
};
use crate::service::MagnetarService;
use crate::web::auth;
use crate::web::auth::AuthState;
use axum::middleware::from_fn_with_state;
use axum::routing::get;
use axum::Router;
use std::sync::Arc;

pub fn create_api_router(service: Arc<MagnetarService>) -> Router {
    Router::new()
        .route("/users/@self", get(handle_user_info_self))
        .route("/users/by-acct/:id", get(handle_user_info_by_acct))
        .route("/users/lookup-many", get(handle_user_by_id_many))
        .route("/users/:id", get(handle_user_info))
        .route("/users/@self/notifications", get(handle_notifications))
        .route(
            "/users/@self/follow-requests",
            get(handle_follow_requests_self),
        )
        .route("/users/@self/following", get(handle_following_self))
        .route("/users/:id/following", get(handle_following))
        .route("/users/@self/followers", get(handle_followers_self))
        .route("/users/:id/followers", get(handle_followers))
        .route("/notes/:id", get(handle_note))
        .route("/streaming", get(handle_streaming))
        .layer(from_fn_with_state(
            AuthState::new(service.clone()),
            auth::auth,
        ))
        .with_state(service)
}
