//! Prometheus metrics endpoint handler.
//!
//! Exposes metrics in Prometheus text format for scraping by monitoring systems.

use axum::response::IntoResponse;
use metrics_exporter_prometheus::PrometheusHandle;
use std::sync::Arc;

/// GET /metrics - Prometheus metrics in text format.
///
/// Returns all registered metrics in Prometheus exposition format.
/// This endpoint bypasses all middleware layers (meter, admission, circuit breaker)
/// to ensure metrics are always accessible for monitoring.
///
/// # Example Response
///
/// ```text
/// # HELP stemedb_sync_cycles_total Total number of anti-entropy sync cycles
/// # TYPE stemedb_sync_cycles_total counter
/// stemedb_sync_cycles_total{peer="127.0.0.1:5001"} 42
/// ```
pub async fn metrics_handler(
    handle: axum::extract::Extension<Arc<PrometheusHandle>>,
) -> impl IntoResponse {
    handle.render()
}
