//! Demo Entropyk - Test du State Machine (ON/OFF/BYPASS)
//!
//! Ce fichier montre comment utiliser OperationalState et CircuitId

use colored::Colorize;
use entropyk_components::state_machine::{CircuitId, OperationalState};

fn print_header(title: &str) {
    println!();
    println!("{}", "═".repeat(60).cyan());
    println!("{}", format!("  {}", title).cyan().bold());
    println!("{}", "═".repeat(60).cyan());
}

fn main() {
    println!(
        "{}",
        "\n╔══════════════════════════════════════════════════════════╗".green()
    );
    println!(
        "{}",
        "║     DEMO ENTROPYK - State Machine (ON/OFF/BYPASS)        ║"
            .green()
            .bold()
    );
    println!(
        "{}",
        "╚══════════════════════════════════════════════════════════╝\n".green()
    );

    print_header("États Opérationnels");

    println!();
    println!("Les composants peuvent être dans 3 états:");
    println!();

    for state in [
        OperationalState::On,
        OperationalState::Off,
        OperationalState::Bypass,
    ] {
        println!("  {:?}:", state);
        println!("    - Actif: {}", state.is_active());
        println!(
            "    - Multiplicateur débit: {:.1}",
            state.mass_flow_multiplier()
        );

        match state {
            OperationalState::On => {
                println!("    → Composant fonctionne normalement");
            }
            OperationalState::Off => {
                println!("    → Composant arrêté, débit = 0");
            }
            OperationalState::Bypass => {
                println!("    → Composant court-circuité (P_in = P_out, h_in = h_out)");
            }
        }
        println!();
    }

    print_header("CircuitId (Multi-Circuit)");

    println!();
    println!("Un système peut avoir jusqu'à 5 circuits indépendants:");
    println!();

    let circuits = vec![
        CircuitId::from_number(0),
        CircuitId::from_number(1),
        CircuitId::default(),
    ];

    for circuit in &circuits {
        println!("  Circuit: {}", circuit);
    }

    println!();
    println!("  Utilisation typique:");
    println!("    - Circuit 0: Boucle réfrigérant principale");
    println!("    - Circuit 1: Circuit eau/glycol");
    println!("    - Circuit 2: Circuit secondaire (optionnel)");

    print_header("Exemples d'utilisation");

    println!();
    println!("  // Créer un système multi-circuit");
    println!("  let mut system = System::new();");
    println!("  system.add_component_to_circuit(compressor, CircuitId(0));");
    println!("  system.add_component_to_circuit(pump, CircuitId(1));");
    println!();
    println!("  // Couplage thermique entre circuits");
    println!("  let coupling = ThermalCoupling::new(");
    println!("      CircuitId(0), // chaud");
    println!("      CircuitId(1), // froid");
    println!("      ThermalConductance::from_watts_per_kelvin(5000.0),");
    println!("  );");

    println!();
    println!("{}", "═".repeat(60).cyan());
    println!(
        "{}",
        "  Voir 'cargo run --bin thermal-coupling' pour la démo complète".cyan()
    );
    println!("{}", "═".repeat(60).cyan());
}
