//! Telemetry gateway
//!
//! The gateway is a small HTTP server for service control-plane signals. It
//! exposes health, version, and metrics routes on one listener and returns a
//! cloneable handle for health mutation.
//!
//! Most applications use this through `efdn::telem::gateway` and pass
//! `efdn::build::meta!()` through lifecycle startup. The direct crate accepts
//! [`GatewayServiceInfo`] for lower-level use.
//!
//! ## Features
//!
//! - `config`: gateway config structs derive `#[config]`.
//! - `alloc-metrics`: adds mimalloc debug routes when the allocator feature is
//!   enabled.
//! - Without `config`, the same structs are manually constructed.
//!
//! ```no_run
//! # async fn run(cfg: efdn_gateway::GatewayConfig) -> Result<(), Box<dyn std::error::Error>> {
//! let gateway = efdn_gateway::start(
//!     cfg,
//!     efdn_gateway::GatewayServiceInfo::new(
//!         efdn_telem::canonical::service::ServiceName::new("worker")?,
//!         efdn_telem::canonical::service::ServiceVersion::new("0.2.0")?,
//!     ),
//! ).await?;
//!
//! let health = gateway.health();
//! let store = health.gate(efdn_gateway::HealthGateName::from_static("store"))?;
//! store.fail(efdn_gateway::HealthCode::from_static("connecting"));
//! store.pass();
//! health.live();
//!
//! gateway.shutdown().await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Routes
//!
//! - `GET /health/live`: liveness. Returns `200` unless the service called
//!   `HealthHandle::dead`.
//! - `GET /health/ready`: readiness. Returns `200` only when the phase is live
//!   and every readiness gate passes or warns.
//! - `GET /health/startup`: startup. Returns `200` after the service reached
//!   live at least once.
//! - `GET /health`: full JSON health snapshot for operators and tests.
//! - `GET /version`: service identity and optional build metadata.
//! - `GET /metrics`: Prometheus text exposition from an attached metrics handle.
//! - `GET /debug/alloc/mimalloc/stats`: mimalloc text statistics when the
//!   `alloc-metrics` feature is enabled.
//! - `GET /debug/alloc/mimalloc/stats.json`: mimalloc JSON statistics when the
//!   `alloc-metrics` feature is enabled.
//! - `POST /debug/alloc/mimalloc/collect`: asks mimalloc to return free memory
//!   to the OS when the `alloc-metrics` feature is enabled.
//!
//! Nomad should use `/health/live` for restart checks and `/health/ready` for
//! rollout/load-balancer checks. Prometheus should scrape `/metrics`.

mod config;
mod error;
mod handle;
mod health;
mod metrics;
mod service;

pub use config::{
    GatewayBind, GatewayConfig, GatewayConfigValueError, GatewayEnabled, GatewayMetricsRoute,
    GatewayRequestTimeout,
};
pub use error::GatewayError;
pub use handle::{GatewayHandle, start};
pub use health::{
    HealthCode, HealthGateHandle, HealthGateName, HealthGateReport, HealthGateStatus, HealthHandle,
    HealthPhase, HealthReport,
};
pub use service::{GatewayBuildInfo, GatewayBuildMeta, GatewayServiceInfo};
