//! Health check endpoints for backtesting service
//!
//! Provides HTTP-based health and readiness endpoints that don't require TLS,
//! allowing Docker Compose health checks to work without client certificates.

use axum::{routing::get, Json, Router};
use serde::Serialize;

/// Health status response
#[derive(Serialize)]
pub struct HealthResponse {
    /// Service status
    pub status: &'static str,
    /// Service name
    pub service: &'static str,
    /// Service version
    pub version: &'static str,
}

/// Creates the health check router with /health and /ready endpoints
pub fn health_router() -> Router {
    Router::new()
        .route("/health", get(health_check))
        .route("/ready", get(readiness_check))
}

/// Liveness probe - indicates service is running
async fn health_check() -> Json<HealthResponse> {
    Json(HealthResponse {
        status: "healthy",
        service: "backtesting",
        version: env!("CARGO_PKG_VERSION"),
    })
}

/// Readiness probe - indicates service is ready to accept requests
async fn readiness_check() -> Json<HealthResponse> {
    // In the future, can add database connection checks here
    // For now, if the service is running, it's ready
    Json(HealthResponse {
        status: "ready",
        service: "backtesting",
        version: env!("CARGO_PKG_VERSION"),
    })
}
