//! Entry point for the Blaze sidecar.
//!
//! Configuration is entirely environmental and both critical values are
//! required, so a misconfigured launch fails immediately and loudly rather than
//! binding a default port next to the working Python container.

use openfut_blaze_host::{serve, HostConfig};

fn main() {
    let cfg = match HostConfig::from_env() {
        Ok(cfg) => cfg,
        Err(e) => {
            eprintln!("openfut-blaze-host: {e}\n");
            eprintln!("Required:");
            eprintln!(
                "  OPENFUT_ADVERTISE        address the game machine uses to reach this host"
            );
            eprintln!(
                "  OPENFUT_BLAZE_HOST_PORT  port to listen on (no default, to avoid colliding"
            );
            eprintln!("                           with the Python backend it runs beside)");
            eprintln!("Optional:");
            eprintln!("  OPENFUT_BIND             advertised-config bind, mirrors the Python");
            eprintln!("                           container's value so nucleusConnect matches");
            eprintln!("  OPENFUT_BLAZE_HOST_BIND  listener bind (defaults to OPENFUT_BIND)");
            eprintln!("  POW_CONTENT_HOST         host:port for POW content");
            eprintln!("  POW_HOST                 host:port for the POW/EASFC API");
            eprintln!("  OPENFUT_BLAZE_TRACE      path for the normalized structural trace");
            eprintln!("  OPENFUT_BLAZE_IDLE_TIMEOUT  seconds, default 300");
            std::process::exit(2);
        }
    };

    if let Err(e) = serve(cfg) {
        eprintln!("openfut-blaze-host: fatal: {e}");
        std::process::exit(1);
    }
}
