use std::f64::consts::PI;

use crate::DEIMOS_RADIUS_M;

pub const SIDEREAL_DAY_S: f64 = 1.263 * 86_400.0;
pub const SYNODIC_DAY_S: f64 = 1.265 * 86_400.0;
pub const AXIAL_TILT_DEG: f64 = 0.0;

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DeimosRotation {
    pub sidereal_period_s: f64,
    pub synodic_period_s: f64,
    pub axial_tilt_deg: f64,
    pub synchronous: bool,
}

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

impl DeimosRotation {
    pub fn new() -> Self {
        Self {
            sidereal_period_s: SIDEREAL_DAY_S,
            synodic_period_s: SYNODIC_DAY_S,
            axial_tilt_deg: AXIAL_TILT_DEG,
            synchronous: true,
        }
    }

    pub fn angular_velocity_rad_s(&self) -> f64 {
        2.0 * PI / self.sidereal_period_s
    }

    pub fn equatorial_speed_m_s(&self) -> f64 {
        self.angular_velocity_rad_s() * DEIMOS_RADIUS_M
    }

    pub fn solar_drift_deg_per_earth_day(&self) -> f64 {
        360.0 * 86_400.0 / self.synodic_period_s
    }
}
