use super::*;

// Process, buffer, and TLS cache metrics.
mod process;
// Connection, quota, and conntrack metrics.
mod connections;
// Rate limiter, upstream, and initial ME metrics.
mod traffic;
// ME lifecycle and relay event metrics.
mod me_lifecycle;
// ME batching and resident-memory metrics.
mod me_buffers;
// ME writer selection, KDF, and hardswap metrics.
mod me_policy;
// Adaptive-floor and writer-cap metrics.
mod me_floor;
// Desync, pool recovery, and refill metrics.
mod me_recovery;
// Bounded per-user and IP-tracker metrics.
mod users;

pub(super) async fn render_metrics(
    stats: &Stats,
    shared_state: &ProxySharedState,
    config: &ProxyConfig,
    ip_tracker: &UserIpTracker,
    tls_cache: Option<&TlsFrontCache>,
    tls_full_cert_budget: &TlsFullCertBudget,
    web_publication: &crate::web::control::WebRuntimePublication,
) -> String {
    let mut out = String::with_capacity(4096);
    let telemetry = stats.telemetry_policy();
    let core_enabled = telemetry.core_enabled;
    let user_enabled = telemetry.user_enabled;
    let me_allows_normal = telemetry.me_level.allows_normal();
    let me_allows_debug = telemetry.me_level.allows_debug();

    process::render(
        &mut out,
        stats,
        shared_state,
        telemetry,
        tls_full_cert_budget,
    );
    super::render_tls_front_profile_health(&mut out, config, tls_cache).await;
    connections::render(&mut out, stats, shared_state, core_enabled);
    traffic::render(
        &mut out,
        stats,
        shared_state,
        config,
        core_enabled,
        me_allows_normal,
        me_allows_debug,
    );
    me_lifecycle::render(&mut out, stats, me_allows_normal);
    me_buffers::render(
        &mut out,
        stats,
        core_enabled,
        me_allows_normal,
        me_allows_debug,
    );
    me_policy::render(&mut out, stats, me_allows_normal, me_allows_debug);
    me_floor::render(&mut out, stats, config, me_allows_normal);
    me_recovery::render(&mut out, stats, me_allows_normal, me_allows_debug);
    users::render(
        &mut out,
        stats,
        config,
        ip_tracker,
        core_enabled,
        user_enabled,
    )
    .await;
    super::web::render(&mut out, web_publication, config);
    out
}
