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

fn main() {
    let mars = deimoss::interactions::marss::ensure_marss_binary_or_simulate();
    let orbit = deimoss::physics::orbit::DeimosOrbit::new();
    let rotation = deimoss::physics::rotation::DeimosRotation::new();
    let landing_site = deimoss::geodata::landing_sites::voltaire_crater();
    let exosphere = deimoss::exosphere::species::reference_composition();
    let thermal = deimoss::environment::thermal::ThermalEnvironment {
        local_time_hours: deimoss::DEIMOS_DAY_HOURS * 0.5,
        latitude_deg: landing_site.latitude_deg,
        shadowed: false,
    };
    let ice = deimoss::resources::water_ice::regolith_ice_deposit();
    let mars_view = deimoss::observation::mars_view::MarsView::sub_mars_default();
    let thermal_k = thermal.surface_temperature_k();
    let startup_score = deimoss::H24_RUNTIME_HOURS as f64
        + mars.orbital_radius_km / 1.0e6
        + mars.orbital_period_days / 365.0
        + mars.orbital_angle_deg / 360.0
        + mars.rotation_period_h / 24.0
        + mars.rotation_angle_deg / 360.0
        + mars.axial_tilt_deg / 90.0
        + mars.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 mars_view.is_visible() { 1.0 } else { 0.0 }
        + if landing_site.name.is_empty() {
            0.0
        } else {
            1.0
        }
        + if matches!(
            mars.mode,
            deimoss::interactions::marss::MarsRuntimeMode::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);
    }
}
