use std::sync::Arc;

use aide::{
    axum::{routing::get, ApiRouter, IntoApiResponse},
    openapi::OpenApi,
    redoc::Redoc,
};
use axum::{response::IntoResponse, Extension};

use crate::extractors::Json;

pub fn routes() -> ApiRouter {
    ApiRouter::new()
        .route("/openapi.json", get(openapi_json))
        .route(
            "/",
            get(Redoc::new("/docs/openapi.json")
                .with_title("starchart docs")
                .axum_handler()),
        )
}

async fn openapi_json(Extension(api): Extension<Arc<OpenApi>>) -> impl IntoApiResponse {
    Json(api).into_response()
}
