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

pub fn equilibrium_temperature_detailed(
    luminosity: f64,
    distance_au: f64,
    albedo: f64,
    emissivity: f64,
) -> f64 {
    let distance_m = distance_au * AU;
    let flux = luminosity / (4.0 * PI * distance_m * distance_m);
    ((flux * (1.0 - albedo)) / (emissivity * STEFAN_BOLTZMANN)).powf(0.25)
}

pub fn yarkovsky_drift_rate(
    radius: f64,
    density: f64,
    semi_major_au: f64,
    albedo: f64,
    obliquity_deg: f64,
) -> f64 {
    let area = PI * radius * radius;
    let mass = sphere_mass(radius, density);
    let distance_m = semi_major_au * AU;
    let flux = SOLAR_LUMINOSITY / (4.0 * PI * distance_m * distance_m);
    let absorbed = flux * (1.0 - albedo) * area;
    let force = absorbed / (3.0e8 * mass);
    let obliquity_rad = obliquity_deg * PI / 180.0;
    force * obliquity_rad.cos() * YEAR
}

pub fn yorp_torque_estimate(radius: f64, semi_major_au: f64, albedo: f64) -> f64 {
    let distance_m = semi_major_au * AU;
    let flux = SOLAR_LUMINOSITY / (4.0 * PI * distance_m * distance_m);
    let area = PI * radius * radius;
    flux * (1.0 - albedo) * area * radius / 3.0e8
}

pub fn sublimation_temperature_estimate(semi_major_au: f64, albedo: f64) -> f64 {
    equilibrium_temperature_detailed(SOLAR_LUMINOSITY, semi_major_au, albedo, 0.9)
}

pub fn thermal_inertia_estimate(density: f64, conductivity: f64, specific_heat: f64) -> f64 {
    (density * conductivity * specific_heat).sqrt()
}

pub fn diurnal_skin_depth(
    conductivity: f64,
    density: f64,
    specific_heat: f64,
    rotation_period: f64,
) -> f64 {
    let diffusivity = conductivity / (density * specific_heat);
    (diffusivity * rotation_period / PI).sqrt()
}
