#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SurfaceCharging {
    pub local_time_hours: f64,
    pub plasma_density_cm3: f64,
    pub photoelectron_current_ua_m2: f64,
}

impl SurfaceCharging {
    pub fn dayside() -> Self {
        Self {
            local_time_hours: 42.0,
            plasma_density_cm3: 200.0,
            photoelectron_current_ua_m2: 0.4,
        }
    }

    pub fn nightside() -> Self {
        Self {
            local_time_hours: 0.0,
            plasma_density_cm3: 40.0,
            photoelectron_current_ua_m2: 0.0,
        }
    }

    pub fn surface_potential_v(&self) -> f64 {
        let diurnal_bias = if (20.0..=65.0).contains(&self.local_time_hours) {
            5.0
        } else {
            -120.0
        };
        diurnal_bias + self.photoelectron_current_ua_m2 * 3.0 - self.plasma_density_cm3 * 0.5
    }

    pub fn dust_lofting_risk(&self) -> f64 {
        (self.surface_potential_v().abs() / 200.0).clamp(0.0, 1.0)
    }
}
