use std::thread;
use std::time::Duration;

fn main() {
    let planet = europas::interactions::jupiters::ensure_jupiters_binary_or_simulate();
    let orbit = europas::physics::orbit::EuropaOrbit::new();
    let rotation = europas::physics::rotation::EuropaRotation::new();
    let landing_site = europas::geodata::landing_sites::thera_macula();
    let exosphere = europas::exosphere::species::reference_composition();
    let thermal = europas::environment::thermal::ThermalEnvironment {
        local_time_hours: europas::EUROPA_DAY_HOURS * 0.5,
        latitude_deg: landing_site.latitude_deg,
        shadowed: false,
    };
    let ice = europas::resources::water_ice::subsurface_ocean();
    let jupiter_view = europas::observation::jupiter_view::JupiterView::sub_jupiter_default();
    let thermal_k = thermal.surface_temperature_k();
    let startup_score = europas::H24_RUNTIME_HOURS as f64
        + planet.orbital_radius_km / 1.0e6
        + planet.orbital_period_days / 365.0
        + planet.orbital_angle_deg / 360.0
        + planet.rotation_period_h / 24.0
        + planet.rotation_angle_deg / 360.0
        + planet.axial_tilt_deg / 90.0
        + planet.surface_speed_m_s / 1_000.0
        + orbit.semi_major_axis_m / 1.0e9
        + orbit.orbital_period_s() / 1.0e6
        + rotation.sidereal_period_s / 1.0e6
        + landing_site.latitude_deg.abs() / 90.0
        + landing_site.longitude_deg.abs() / 180.0
        + exosphere.len() as f64
        + thermal_k / 1_000.0
        + ice.estimated_mass_kg.log10().max(0.0)
        + if jupiter_view.is_visible() { 1.0 } else { 0.0 }
        + if landing_site.name.is_empty() {
            0.0
        } else {
            1.0
        }
        + if matches!(
            planet.mode,
            europas::interactions::jupiters::JupiterRuntimeMode::Binary
        ) {
            1.0
        } else {
            0.5
        };
    let heartbeat = if startup_score.is_finite() && startup_score > 0.0 {
        Duration::from_secs(60)
    } else {
        Duration::from_secs(5)
    };

    loop {
        thread::sleep(heartbeat);
    }
}
