use axum::{extract::State, http::HeaderMap, Json};
use serde::Serialize;
use std::sync::Arc;
use crate::callback::AuthCallback;
use crate::errors::AppError;
use crate::handlers::admin::validate_system_admin;
use crate::services::EmailService;
use crate::AppState;
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SanctionsStatsResponse {
pub address_count: usize,
pub country_count: usize,
pub cache_age_secs: Option<u64>,
}
pub async fn get_sanctions_stats<C: AuthCallback, E: EmailService>(
State(state): State<Arc<AppState<C, E>>>,
headers: HeaderMap,
) -> Result<Json<SanctionsStatsResponse>, AppError> {
validate_system_admin(&state, &headers).await?;
let stats = state.sanctions_service.stats().await;
Ok(Json(SanctionsStatsResponse {
address_count: stats.address_count,
country_count: stats.country_count,
cache_age_secs: stats.cache_age_secs,
}))
}
pub async fn refresh_sanctions<C: AuthCallback, E: EmailService>(
State(state): State<Arc<AppState<C, E>>>,
headers: HeaderMap,
) -> Result<Json<SanctionsStatsResponse>, AppError> {
validate_system_admin(&state, &headers).await?;
state.sanctions_service.refresh().await?;
let stats = state.sanctions_service.stats().await;
Ok(Json(SanctionsStatsResponse {
address_count: stats.address_count,
country_count: stats.country_count,
cache_age_secs: stats.cache_age_secs,
}))
}