use mercurys::atmosphere::climate::MercuryThermalState;
use mercurys::atmosphere::heatwaves::{ThermalCycle, hot_pole_max_temp_k, warm_pole_max_temp_k};
use mercurys::atmosphere::layers::{all_species, effective_temperature_k, mean_solar_irradiance};
use mercurys::atmosphere::winds::{magnetopause_standoff_m, solar_wind_dynamic_pressure};
use mercurys::lighting::day_night::DayNightCycle;
use mercurys::lighting::seasons::MercurySeason;

fn main() {
    println!("=== Mercury Exosphere ===");
    let temp_k = 440.0;
    for species in &all_species() {
        let d_surface = species.number_density_at(0.0, temp_k);
        let d_100km = species.number_density_at(100_000.0, temp_k);
        let escape = species.jeans_escape_rate(temp_k);
        println!(
            "  {}: n(0)={:.2e} n(100km)={:.2e} escape={:.2e} 1/s",
            species.name, d_surface, d_100km, escape
        );
    }

    println!("\n=== Solar Wind Interaction ===");
    let p = solar_wind_dynamic_pressure();
    let r_mp = magnetopause_standoff_m();
    println!("  Dynamic pressure: {:.2e} Pa", p);
    println!(
        "  Magnetopause standoff: {:.0} km ({:.2} Mercury radii)",
        r_mp / 1000.0,
        r_mp / 2_439_700.0
    );

    println!("\n=== Thermal State ===");
    for (name, state) in [
        ("Perihelion", MercuryThermalState::at_perihelion()),
        ("Mean", MercuryThermalState::mean()),
        ("Aphelion", MercuryThermalState::at_aphelion()),
    ] {
        let sub = state.subsolar_temperature_k();
        let eff = state.effective_temperature_k();
        let flux = state.solar_flux();
        println!(
            "  {}: T_sub={:.0}K  T_eff={:.0}K  flux={:.0} W/m²",
            name, sub, eff, flux
        );
    }

    println!("\n=== Thermal Cycles ===");
    let eq = ThermalCycle::equatorial();
    let polar = ThermalCycle::polar();
    println!(
        "  Equatorial: {:.0}K — {:.0}K (swing={:.0}K)",
        eq.nightside_temp_k,
        eq.subsolar_temp_k,
        eq.temperature_swing_k()
    );
    println!(
        "  Polar: {:.0}K — {:.0}K (swing={:.0}K)",
        polar.nightside_temp_k,
        polar.subsolar_temp_k,
        polar.temperature_swing_k()
    );
    println!("  Hot pole (perihelion): {:.0}K", hot_pole_max_temp_k());
    println!("  Warm pole (aphelion):  {:.0}K", warm_pole_max_temp_k());

    println!("\n=== Orbital Seasons ===");
    let peri = MercurySeason::perihelion();
    let aph = MercurySeason::aphelion();
    println!("  Perihelion flux: {:.0} W/m²", peri.solar_flux_w_m2);
    println!("  Aphelion flux:   {:.0} W/m²", aph.solar_flux_w_m2);
    println!(
        "  Flux ratio:      {:.2}x",
        MercurySeason::perihelion_to_aphelion_flux_ratio()
    );

    let cycle = DayNightCycle::new();
    println!("\n=== Day/Night ===");
    println!("  Solar day: {:.1} Earth days", cycle.solar_day_s / 86400.0);
    println!(
        "  Sidereal day: {:.1} Earth days",
        cycle.sidereal_day_s / 86400.0
    );

    println!("\n=== Global Radiative ===");
    println!(
        "  Mean solar irradiance: {:.0} W/m²",
        mean_solar_irradiance()
    );
    println!(
        "  Effective temperature: {:.0} K",
        effective_temperature_k()
    );
}
