use sciforge::hub::domain::geology::tectonics::{airy_root, isostatic_equilibrium};

pub struct CraterRim {
    pub crater_name: &'static str,
    pub rim_height_m: f64,
    pub diameter_km: f64,
}

impl CraterRim {
    pub fn depth_to_diameter_ratio(&self) -> f64 {
        if self.diameter_km < 10.3 {
            0.2
        } else {
            0.15 * (10.3 / self.diameter_km).powf(0.3)
        }
    }

    pub fn estimated_floor_depth_m(&self) -> f64 {
        self.diameter_km * 1000.0 * self.depth_to_diameter_ratio()
    }

    pub fn isostatic_root_m(&self) -> f64 {
        airy_root(
            self.rim_height_m,
            crate::CRUST_DENSITY,
            crate::MANTLE_DENSITY,
        )
    }
}

pub fn major_crater_rims() -> Vec<CraterRim> {
    vec![
        CraterRim {
            crater_name: "Caloris",
            rim_height_m: 2000.0,
            diameter_km: 1550.0,
        },
        CraterRim {
            crater_name: "Rachmaninoff",
            rim_height_m: 1500.0,
            diameter_km: 306.0,
        },
        CraterRim {
            crater_name: "Rembrandt",
            rim_height_m: 1200.0,
            diameter_km: 716.0,
        },
        CraterRim {
            crater_name: "Beethoven",
            rim_height_m: 1000.0,
            diameter_km: 630.0,
        },
        CraterRim {
            crater_name: "Tolstoj",
            rim_height_m: 900.0,
            diameter_km: 510.0,
        },
        CraterRim {
            crater_name: "Dostoevskij",
            rim_height_m: 800.0,
            diameter_km: 411.0,
        },
    ]
}

pub struct ScarpRidge {
    pub name: &'static str,
    pub peak_height_m: f64,
    pub length_km: f64,
}

pub fn major_scarp_ridges() -> Vec<ScarpRidge> {
    vec![
        ScarpRidge {
            name: "Enterprise Rupes",
            peak_height_m: 3000.0,
            length_km: 820.0,
        },
        ScarpRidge {
            name: "Discovery Rupes",
            peak_height_m: 2000.0,
            length_km: 650.0,
        },
        ScarpRidge {
            name: "Victoria Rupes",
            peak_height_m: 1500.0,
            length_km: 400.0,
        },
    ]
}

pub fn highest_point_estimate_m() -> f64 {
    crate::HIGHEST_POINT_M
}

pub fn lowest_point_estimate_m() -> f64 {
    crate::LOWEST_POINT_M
}

pub fn total_relief_m() -> f64 {
    crate::HIGHEST_POINT_M - crate::LOWEST_POINT_M
}

pub fn isostatic_elevation(crust_thickness_m: f64) -> f64 {
    isostatic_equilibrium(
        crust_thickness_m,
        crate::CRUST_DENSITY,
        crate::MANTLE_DENSITY,
    )
}
