#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SolarIllumination {
    pub incidence_deg: f64,
    pub phase_angle_deg: f64,
}

pub fn subsolar_longitude_deg(europa_day_fraction: f64) -> f64 {
    360.0 * europa_day_fraction.rem_euclid(1.0) - 180.0
}

pub fn solar_elevation_deg(latitude_deg: f64, local_time_hours: f64) -> f64 {
    let hour_angle_deg = (local_time_hours - 42.6) * (360.0 / 85.2);
    (90.0 - latitude_deg.abs() - hour_angle_deg.abs() * 0.6).clamp(-90.0, 90.0)
}

pub fn illumination(
    latitude_deg: f64,
    local_time_hours: f64,
    phase_angle_deg: f64,
) -> SolarIllumination {
    let elevation = solar_elevation_deg(latitude_deg, local_time_hours);
    SolarIllumination {
        incidence_deg: (90.0 - elevation).clamp(0.0, 180.0),
        phase_angle_deg,
    }
}
