use crate::BodyId;
use crate::math::matrix::mat_r;
use crate::math::vector::vec_p;
use crate::math::vector::vec_pv;
use crate::pos_eph::equ_orbit::OrbElem;
use super::{vsop2013_emb, vsop2013_jupiter, vsop2013_mars, vsop2013_mercury, vsop2013_saturn, vsop2013_venus, TO_ICRS};

///
/// # Arguments
/// # Returns
///
pub fn get_orb_elm(mjd_tdb: f64, body: &BodyId) -> OrbElem {
    match body {
        BodyId::MERCURY | BodyId::MERCURYB => vsop2013_mercury::mercury(mjd_tdb),
        BodyId::VENUS | BodyId::VENUSB => vsop2013_venus::venus(mjd_tdb),
        BodyId::EMB => vsop2013_emb::emb(mjd_tdb),
        BodyId::MARS | BodyId::MARSB => vsop2013_mars::mars(mjd_tdb),
        BodyId::JUPITER | BodyId::JUPITERB => vsop2013_jupiter::jupiter(mjd_tdb),
        BodyId::SATURN | BodyId::SATURNB => vsop2013_saturn::saturn(mjd_tdb),
        _ => OrbElem {
            mu: f64::NAN,
            mjd0: mjd_tdb,
            a: f64::NAN,
            l: f64::NAN,
            k: f64::NAN,
            h: f64::NAN,
            q: f64::NAN,
            p: f64::NAN,
        },
    }
}

///
/// # Arguments
/// # Returns
///
pub fn get_icrs_pv(mjd_tdb: f64, body: &BodyId) -> vec_pv::VecPv {
    let orb_el = get_orb_elm(mjd_tdb, body);
    let out = orb_el.get_pv();
    mat_r::mul_pv(&TO_ICRS, &out)
}

///
/// # Arguments
/// # Returns
///
pub fn get_icrs_p(mjd_tdb: f64, body: &BodyId) -> vec_p::VecP {
    let orb_el = get_orb_elm(mjd_tdb, body);
    let out = orb_el.get_p();
    mat_r::mul_p(&TO_ICRS, &out)
}
