use actix_web::{HttpResponse, web};
use serde::Serialize;
use service::{AppService, user::config::UserConfigResponse};
use session::Session;

use crate::error::ApiError;

fn ok_json<T: Serialize>(data: T) -> Result<HttpResponse, ApiError> {
    Ok(HttpResponse::Ok().json(data))
}

#[utoipa::path(
    get,
    path = "/api/v1/user/config",
    responses(
        (status = 200, body = UserConfigResponse)
    ),
    tag = "user"
)]
pub async fn user_config(
    service: web::Data<AppService>,
    session: Session,
) -> Result<HttpResponse, ApiError> {
    let config = service.user_config(&session).await?;
    ok_json(config)
}
