use super::{HealthRegistry, HealthStatus};
use actix_web::http::StatusCode;
use actix_web::{web, HttpResponse, Responder};
use std::sync::Arc;
pub async fn live() -> impl Responder {
HttpResponse::Ok().json(serde_json::json!({"status": "healthy"}))
}
pub async fn ready(registry: web::Data<Arc<HealthRegistry>>) -> HttpResponse {
let report = registry.check_all().await;
let status = match report.overall {
HealthStatus::Healthy | HealthStatus::Degraded => StatusCode::OK,
HealthStatus::Unhealthy => StatusCode::SERVICE_UNAVAILABLE,
};
HttpResponse::build(status).json(report)
}
pub fn configure_health_routes(cfg: &mut web::ServiceConfig) {
cfg.service(web::resource("/health/live").route(web::get().to(live)));
cfg.service(web::resource("/health/ready").route(web::get().to(ready)));
}