use axum::{extract::State, response::Json};
use serde_json::Value;

use crate::error::{ApiError, Result};
use crate::models::{ApiResponse, ChurchConfig};
use crate::services::ConfigService;
use crate::utils::response::success_response;
use crate::AppState;

pub async fn get_public_config(State(state): State<AppState>) -> Result<Json<Value>> {
    let public_config = ConfigService::get_public_config(&state.pool).await?
        .ok_or_else(|| ApiError::NotFound("Church config not found".to_string()))?;
    
    Ok(Json(public_config))
}

pub async fn get_admin_config(State(state): State<AppState>) -> Result<Json<ApiResponse<ChurchConfig>>> {
    let config = ConfigService::get_admin_config(&state.pool).await?
        .ok_or_else(|| ApiError::NotFound("Church config not found".to_string()))?;
    
    Ok(success_response(config))
}

pub async fn get_recurring_types() -> Json<Vec<&'static str>> {
    Json(crate::utils::validation::get_valid_recurring_types())
}
