//! Exemple: Pompe
//!
//! Courbes de performance polynomiales.
//!
//! Exécuter: cargo run -p entropyk-demo --bin pump

use entropyk_components::port::{FluidId, Port};
use entropyk_components::pump::{Pump, PumpCurves};
use entropyk_core::{Enthalpy, Pressure};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("=== Exemple: Pompe ===\n");

    let curves = PumpCurves::quadratic(30.0, -10.0, -50.0, 0.5, 0.3, -0.5)?;

    let inlet = Port::new(
        FluidId::new("Water"),
        Pressure::from_bar(1.0),
        Enthalpy::from_joules_per_kg(100_000.0),
    );
    let outlet = Port::new(
        FluidId::new("Water"),
        Pressure::from_bar(1.0),
        Enthalpy::from_joules_per_kg(100_000.0),
    );

    let pump = Pump::new(curves, inlet, outlet, 1000.0)?;

    println!("Pompe créée:");
    println!("  - Fluide: {}", pump.fluid_id());
    println!("  - Densité: {} kg/m³", pump.fluid_density());

    for q in [0.0, 0.05, 0.1, 0.2] {
        let head = pump.curves().head_at_flow(q);
        let eff = pump.curves().efficiency_at_flow(q);
        println!(
            "  - Q={:.2} m³/s: H={:.2} m, η={:.1}%",
            q,
            head,
            eff * 100.0
        );
    }

    Ok(())
}
