//! StemeDB Spine Simulator Binary
//!
// CLI binaries use println! for user-facing output (not tracing)
#![allow(clippy::print_stdout, clippy::print_stderr)]
//!
//! This binary validates the "Spine" (Durability + Schema + Ingestion) by simulating
//! multiple agents creating, signing, and writing assertions to the WAL, which are then
//! asynchronously ingested into the Storage Engine.
//!
//! # Usage
//!
//! ```bash
//! cargo run --bin stemedb-sim
//! ```
//!
//! # Exit Codes
//!
//! - 0: Simulation completed successfully
//! - 1: Simulation completed with verification errors
//! - 2: Simulation setup failed (fatal error)

use std::process::ExitCode;
use stemedb_sim::{run_simulation, SimulationConfig};

#[tokio::main]
async fn main() -> ExitCode {
    // Initialize tracing
    tracing_subscriber::fmt::init();

    // Run with default configuration
    let config = SimulationConfig::default();

    match run_simulation(config).await {
        Ok(result) => {
            println!("\n{}", result.summary());

            if result.is_success() {
                println!("\n🎉 The Arena: Spine validation PASSED.");
                ExitCode::SUCCESS
            } else {
                println!("\n💥 The Arena: Spine validation FAILED.");
                for err in &result.errors {
                    println!("  [Tick {}] {:?}: {}", err.tick, err.kind, err.message);
                }
                ExitCode::from(1)
            }
        }
        Err(e) => {
            eprintln!("\n🔥 Fatal setup error: {}", e);
            ExitCode::from(2)
        }
    }
}
