use std::sync::Arc;

use axum::{extract::State, response::IntoResponse, Json};
use control_center::AppState;
use ontoref_ontology::api::ApiRouteEntry;
use serde_json::json;

pub async fn api_catalog(State(_state): State<Arc<AppState>>) -> impl IntoResponse {
    let mut routes: Vec<&'static ApiRouteEntry> = inventory::iter::<ApiRouteEntry>().collect();
    routes.sort_by(|a, b| a.path.cmp(b.path).then(a.method.cmp(b.method)));
    Json(json!({ "service": "control-center", "routes": routes }))
}
