use sciforge::hub::domain::geology::dating::radioactive_decay;

pub struct SpaceWeathering {
    pub micrometeorite_flux_rate: f64,
    pub solar_wind_sputtering_rate: f64,
    pub npfp_production_rate: f64,
}

impl Default for SpaceWeathering {
    fn default() -> Self {
        Self::new()
    }
}

impl SpaceWeathering {
    pub fn new() -> Self {
        Self {
            micrometeorite_flux_rate: crate::MICROMETEORITE_FLUX,
            solar_wind_sputtering_rate: crate::SOLAR_WIND_SPUTTERING_RATE,
            npfp_production_rate: crate::NPFP_PRODUCTION_RATE,
        }
    }

    pub fn regolith_gardening_depth_m(&self, time_years: f64) -> f64 {
        (time_years / 1.0e6).sqrt() * 0.01
    }

    pub fn surface_darkening_factor(&self, exposure_myr: f64) -> f64 {
        1.0 - (-exposure_myr / crate::DARKENING_TIMESCALE_MYR).exp()
    }

    pub fn global_sputtering_rate_kg_s(&self) -> f64 {
        let surface_area =
            4.0 * std::f64::consts::PI * crate::physics::orbit::MERCURY_RADIUS.powi(2);
        let effective_fraction = 0.05;
        self.solar_wind_sputtering_rate * surface_area * effective_fraction
    }

    pub fn turnover_period_years(&self) -> f64 {
        1.0e7
    }

    pub fn spectral_reddening_per_myr(&self) -> f64 {
        0.002
    }
}

pub fn thermal_fatigue_crack_growth_rate(temp_amplitude_k: f64, cycles_per_solar_day: f64) -> f64 {
    let stress_intensity = 0.001 * temp_amplitude_k;
    let c = 1.0e-12;
    let m = 3.0;
    c * stress_intensity.powf(m) * cycles_per_solar_day
}

pub fn equatorial_temp_swing() -> f64 {
    crate::SUBSOLAR_TEMP_K - crate::NIGHTSIDE_TEMP_K
}

pub fn cosmogenic_production_rate() -> f64 {
    200.0
}

pub fn radiogenic_fraction_remaining(half_life_years: f64, time_years: f64) -> f64 {
    radioactive_decay(1.0, half_life_years, time_years)
}
