use axum::{Json, Router, extract::State, routing::get};
use serde::Serialize;
use utoipa::ToSchema;

use crate::AppState;

/// Public, non-sensitive instance configuration the SPA needs before login.
#[derive(Serialize, ToSchema)]
pub(crate) struct ConfigView {
    /// User-facing product name.
    pub app_name: String,
    /// Default UI/content language (i18n key, e.g. "sv").
    pub default_language: String,
    /// Default display timezone (IANA name). Storage is UTC; this is a display hint.
    pub default_timezone: String,
}

#[utoipa::path(get, path = "/api/config", responses((status = 200, body = ConfigView)))]
pub(crate) async fn get_config(State(state): State<AppState>) -> Json<ConfigView> {
    Json(ConfigView {
        app_name: state.app_name.clone(),
        default_language: state.default_language.clone(),
        default_timezone: state.default_timezone.clone(),
    })
}

pub(crate) fn routes() -> Router<AppState> {
    Router::new().route("/api/config", get(get_config))
}
