use crate::config::parameters::*;

pub fn collisional_lifetime_estimate(radius: f64, semi_major_au: f64) -> f64 {
    let size_km = radius / 1000.0;
    let base = if semi_major_au < 2.8 && semi_major_au > 2.0 {
        1.0e9 * YEAR
    } else {
        5.0e9 * YEAR
    };
    base * (size_km / 10.0).powf(0.5)
}

pub fn yarkovsky_semi_major_drift(
    radius: f64,
    density: f64,
    semi_major_au: f64,
    obliquity_deg: f64,
) -> f64 {
    let diameter_m = 2.0 * radius;
    let base_rate = 2.7e-4 / (diameter_m * density / 2500.0);
    let obliquity_rad = obliquity_deg * PI / 180.0;
    base_rate * obliquity_rad.cos() * (2.5 / semi_major_au).sqrt()
}

pub fn spin_up_timescale(
    radius: f64,
    density: f64,
    semi_major_au: f64,
    rotation_period: f64,
) -> f64 {
    let mass = sphere_mass(radius, density);
    let inertia = 0.4 * mass * radius * radius;
    let omega = 2.0 * PI / rotation_period;
    let angular_momentum = inertia * omega;
    let distance_m = semi_major_au * AU;
    let flux = SOLAR_LUMINOSITY / (4.0 * PI * distance_m * distance_m);
    let torque = flux * PI * radius * radius * radius / 3.0e8;
    if torque < 1.0e-50 {
        return f64::INFINITY;
    }
    angular_momentum / torque
}

pub fn space_weathering_timescale(semi_major_au: f64) -> f64 {
    1.0e6 * YEAR * (semi_major_au / 1.0).powi(2)
}

pub fn regolith_depth_estimate(radius: f64, surface_gravity: f64) -> f64 {
    let escape = (2.0 * surface_gravity * radius).sqrt();
    let base_depth = 0.01 * radius;
    let retention = (escape / 1.0).min(1.0);
    base_depth * retention
}
