use crate::COSMIC_RAY_DOSE_MSV_DAY;

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RadiationEnvironment {
    pub jupiter_magnetosphere_flux: f64,
    pub galactic_cosmic_ray_dose_msv_day: f64,
    pub regolith_shielding_g_cm2: f64,
}

impl RadiationEnvironment {
    pub fn nominal_surface() -> Self {
        Self {
            jupiter_magnetosphere_flux: 4.0,
            galactic_cosmic_ray_dose_msv_day: COSMIC_RAY_DOSE_MSV_DAY,
            regolith_shielding_g_cm2: 0.0,
        }
    }

    pub fn sheltered(regolith_depth_m: f64) -> Self {
        Self {
            jupiter_magnetosphere_flux: 0.8,
            galactic_cosmic_ray_dose_msv_day: COSMIC_RAY_DOSE_MSV_DAY,
            regolith_shielding_g_cm2: regolith_depth_m.max(0.0) * 90.0,
        }
    }

    pub fn effective_daily_dose_msv(&self) -> f64 {
        let attenuation = (-self.regolith_shielding_g_cm2 / 180.0).exp();
        self.galactic_cosmic_ray_dose_msv_day * attenuation + self.jupiter_magnetosphere_flux * 1.5
    }
}

pub fn annual_crew_dose_msv(environment: RadiationEnvironment) -> f64 {
    environment.effective_daily_dose_msv() * 365.25
}
