use crate::frame::constant::*;
use crate::math::angle::*;
use crate::phys_eph::phys_eph::PhysPrm;

pub fn sun() -> PhysPrm {
    PhysPrm {
        rad_mean: 695700.0 / AU,
        rad_equ: 695700.0 / AU,
        flatt_pol: 0.0,
        mag_v10: -26.78,
    }
}

pub fn mercury() -> PhysPrm {
    PhysPrm {
        rad_mean: 2439.4 / AU,
        rad_equ: 2440.53 / AU,
        flatt_pol: (2440.53 - 2438.26) / 2440.53,
        mag_v10: -0.42,
    }
}

pub fn vis_mag_mercury(dist_sun_body: f64, dist_obs_body: f64, phase_angl: f64) -> f64 {
    let phase_angl_d = phase_angl * RADDEG;
    let pp = mercury();
    let v_dist = pp.vis_mag(dist_sun_body, dist_obs_body);
    let v_phase = (3.8e-2 + (-2.73e-4 + 2.0e-6 * phase_angl_d) * phase_angl_d) * phase_angl_d;
    v_dist + v_phase
}

pub fn venus() -> PhysPrm {
    PhysPrm {
        rad_mean: 6051.8 / AU,
        rad_equ: 6051.8 / AU,
        flatt_pol: 0.0,
        mag_v10: -4.40,
    }
}

pub fn vis_mag_venus(dist_sun_body: f64, dist_obs_body: f64, phase_angl: f64) -> f64 {
    let phase_angl_d = phase_angl * RADDEG;
    let pp = venus();
    let v_dist = pp.vis_mag(dist_sun_body, dist_obs_body);
    let v_phase = (0.09e-2 + (2.39e-4 - 0.65e-6 * phase_angl_d) * phase_angl_d) * phase_angl_d;
    v_dist + v_phase
}

pub fn earth() -> PhysPrm {
    PhysPrm {
        rad_mean: 6371.0084 / AU,
        rad_equ: 6378.1366 / AU,
        flatt_pol: (6378.1366 - 6356.7519) / 6378.1366,
        mag_v10: -3.86,
    }
}

pub fn mars() -> PhysPrm {
    PhysPrm {
        rad_mean: 3389.50 / AU,
        rad_equ: 3396.19 / AU,
        flatt_pol: (3396.19 - 3376.20) / 3396.19,
        mag_v10: -1.52,
    }
}

pub fn vis_mag_mars(dist_sun_body: f64, dist_obs_body: f64, phase_angl: f64) -> f64 {
    let phase_angl_d = phase_angl * RADDEG;
    let pp = mars();
    let v_dist = pp.vis_mag(dist_sun_body, dist_obs_body);
    let v_phase = 0.016 * phase_angl_d;
    v_dist + v_phase
}

pub fn jupiter() -> PhysPrm {
    PhysPrm {
        rad_mean: 69911.0 / AU,
        rad_equ: 71492.0 / AU,
        flatt_pol: (71492.0 - 66854.0) / 71492.0,
        mag_v10: -9.40,
    }
}

pub fn vis_mag_jupiter(dist_sun_body: f64, dist_obs_body: f64, phase_angl: f64) -> f64 {
    let phase_angl_d = phase_angl * RADDEG;
    let pp = jupiter();
    let v_dist = pp.vis_mag(dist_sun_body, dist_obs_body);
    let v_phase = 0.005 * phase_angl_d;
    v_dist + v_phase
}

pub fn saturn() -> PhysPrm {
    PhysPrm {
        rad_mean: 58232.0 / AU,
        rad_equ: 60268.0 / AU,
        flatt_pol: (60268.0 - 54364.0) / 60268.0,
        mag_v10: -8.88,
    }
}

pub fn vis_mag_saturn(dist_sun_body: f64, dist_obs_body: f64, phase_angl: f64, lat_sep: f64) -> f64 {
    let phase_angl_d = phase_angl * RADDEG;
    let pp = saturn();
    let v_dist = pp.vis_mag(dist_sun_body, dist_obs_body);
    let v_phase = 0.044 * phase_angl_d;
    let v_ring = vis_mag_satring(lat_sep);
    v_dist + v_phase + v_ring
}

pub fn saturn_ring() -> PhysPrm {
    PhysPrm {
        rad_mean: 136770.0 / AU,
        rad_equ: 136770.0 / AU,
        flatt_pol: 0.0,
        mag_v10: 0.0,
    }
}

pub fn vis_mag_satring(lat_sep: f64) -> f64 {
    let sinb = lat_sep.abs().sin();
    -2.60 * sinb + 1.25 * sinb * sinb
}

pub fn satring_opening(lat_sep: f64) -> f64 {
    lat_sep.abs().sin()
}

pub fn uranus() -> PhysPrm {
    PhysPrm {
        rad_mean: 25362.0 / AU,
        rad_equ: 25559.0 / AU,
        flatt_pol: (25559.0 - 24973.0) / 25559.0,
        mag_v10: -7.19,
    }
}

pub fn vis_mag_uranus(dist_sun_body: f64, dist_obs_body: f64, phase_angl: f64) -> f64 {
    let phase_angl_d = phase_angl * RADDEG;
    let pp = uranus();
    let v_dist = pp.vis_mag(dist_sun_body, dist_obs_body);
    let v_phase = 0.0028 * phase_angl_d;
    v_dist + v_phase
}

pub fn neptune() -> PhysPrm {
    PhysPrm {
        rad_mean: 24622.0 / AU,
        rad_equ: 24764.0 / AU,
        flatt_pol: (24764.0 - 24341.0) / 24764.0,
        mag_v10: -6.87,
    }
}

pub fn moon() -> PhysPrm {
    PhysPrm {
        rad_mean: 1737.4 / AU,
        rad_equ: 1737.4 / AU,
        flatt_pol: 0.0,
        mag_v10: 0.21,
    }
}

pub fn vis_mag_moon(dist_sun_body: f64, dist_obs_body: f64, phase_angl: f64) -> f64 {
    let phase_angl_d = phase_angl * RADDEG;
    let pp = moon();
    let v_dist = pp.vis_mag(dist_sun_body, dist_obs_body);
    let v_phase = (3.38e-2 + (-1.07e-4 + 0.99e-6 * phase_angl_d) * phase_angl_d) * phase_angl_d;
    v_dist + v_phase
}

pub fn phobos() -> PhysPrm {
    PhysPrm {
        rad_mean: 11.08 / AU,
        rad_equ: 13.0 / AU,
        flatt_pol: (13.0 - 9.1) / 13.0,
        mag_v10: 11.80,
    }
}

pub fn deimos() -> PhysPrm {
    PhysPrm {
        rad_mean: 6.2 / AU,
        rad_equ: 7.8 / AU,
        flatt_pol: (7.8 - 5.1) / 7.8,
        mag_v10: 12.89,
    }
}

pub fn io() -> PhysPrm {
    PhysPrm {
        rad_mean: 1821.49 / AU,
        rad_equ: 1829.4 / AU,
        flatt_pol: (1829.4 - 1815.7) / 1829.4,
        mag_v10: -1.68,
    }
}

pub fn europa() -> PhysPrm {
    PhysPrm {
        rad_mean: 1560.8 / AU,
        rad_equ: 1562.6 / AU,
        flatt_pol: (1562.6 - 1559.5) / 1562.6,
        mag_v10: -1.41,
    }
}

pub fn ganymede() -> PhysPrm {
    PhysPrm {
        rad_mean: 2631.2 / AU,
        rad_equ: 2631.2 / AU,
        flatt_pol: 0.0,
        mag_v10: -2.09,
    }
}

pub fn callisto() -> PhysPrm {
    PhysPrm {
        rad_mean: 2410.3 / AU,
        rad_equ: 2410.3 / AU,
        flatt_pol: 0.0,
        mag_v10: -1.05,
    }
}

pub fn amalthea() -> PhysPrm {
    PhysPrm {
        rad_mean: 83.5 / AU,
        rad_equ: 125.0 / AU,
        flatt_pol: (125.0 - 64.0) / 125.0,
        mag_v10: 7.40,
    }
}

pub fn himalia() -> PhysPrm {
    PhysPrm {
        rad_mean: 85.0 / AU,
        rad_equ: 85.0 / AU,
        flatt_pol: 0.0,
        mag_v10: 8.14,
    }
}

pub fn mimas() -> PhysPrm {
    PhysPrm {
        rad_mean: 198.2 / AU,
        rad_equ: 207.8 / AU,
        flatt_pol: (207.8 - 190.6) / 207.8,
        mag_v10: 3.30,
    }
}

pub fn enceladus() -> PhysPrm {
    PhysPrm {
        rad_mean: 252.1 / AU,
        rad_equ: 256.6 / AU,
        flatt_pol: (256.6 - 248.3) / 256.6,
        mag_v10: 2.10,
    }
}

pub fn tethys() -> PhysPrm {
    PhysPrm {
        rad_mean: 531.0 / AU,
        rad_equ: 538.4 / AU,
        flatt_pol: (538.4 - 526.3) / 538.4,
        mag_v10: 0.60,
    }
}

pub fn dione() -> PhysPrm {
    PhysPrm {
        rad_mean: 561.4 / AU,
        rad_equ: 563.4 / AU,
        flatt_pol: (563.4 - 559.6) / 563.4,
        mag_v10: 0.88, //0.8
    }
}

pub fn rhea() -> PhysPrm {
    PhysPrm {
        rad_mean: 763.5 / AU,
        rad_equ: 765.0 / AU,
        flatt_pol: (765.0 - 762.4) / 765.0,
        mag_v10: 0.16, //0.1
    }
}

pub fn titan() -> PhysPrm {
    PhysPrm {
        rad_mean: 2575.0 / AU,
        rad_equ: 2575.15 / AU,
        flatt_pol: (2575.15 - 2574.47) / 2575.15,
        mag_v10: -1.28,
    }
}

pub fn hyperion() -> PhysPrm {
    PhysPrm {
        rad_mean: 135.0 / AU,
        rad_equ: 180.1 / AU,
        flatt_pol: (180.1 - 102.7) / 180.1,
        mag_v10: 4.63,
    }
}

pub fn iapetus() -> PhysPrm {
    PhysPrm {
        rad_mean: 734.7 / AU,
        rad_equ: 745.7 / AU,
        flatt_pol: (745.7 - 712.1) / 745.7,
        mag_v10: 1.50,
    }
}

pub fn janus() -> PhysPrm {
    PhysPrm {
        rad_mean: 89.2 / AU,
        rad_equ: 101.7 / AU,
        flatt_pol: (101.7 - 76.3) / 101.7,
        mag_v10: 4.40,
    }
}

pub fn ariel() -> PhysPrm {
    PhysPrm {
        rad_mean: 578.9 / AU,
        rad_equ: 581.1 / AU,
        flatt_pol: (581.1 - 577.7) / 581.1,
        mag_v10: 1.45,
    }
}

pub fn umbriel() -> PhysPrm {
    PhysPrm {
        rad_mean: 584.7 / AU,
        rad_equ: 584.7 / AU,
        flatt_pol: 0.0,
        mag_v10: 2.10,
    }
}

pub fn titania() -> PhysPrm {
    PhysPrm {
        rad_mean: 788.9 / AU,
        rad_equ: 788.9 / AU,
        flatt_pol: 0.0,
        mag_v10: 1.02,
    }
}

pub fn oberon() -> PhysPrm {
    PhysPrm {
        rad_mean: 761.9 / AU,
        rad_equ: 761.9 / AU,
        flatt_pol: 0.0,
        mag_v10: 1.23,
    }
}

pub fn triton() -> PhysPrm {
    PhysPrm {
        rad_mean: 1352.6 / AU,
        rad_equ: 1352.6 / AU,
        flatt_pol: 0.0,
        mag_v10: -1.24,
    }
}

pub fn pluto() -> PhysPrm {
    PhysPrm {
        rad_mean: 1188.3 / AU,
        rad_equ: 1188.3 / AU,
        flatt_pol: 0.0,
        mag_v10: -1.01, //-0.44
        // mag_pha1: 0.0,  //0.15
    }
}

pub fn ceres() -> PhysPrm {
    PhysPrm {
        rad_mean: 470.0 / AU,
        rad_equ: 487.3 / AU,
        flatt_pol: (487.3 - 446.0) / 487.3,
        mag_v10: 3.33, //3.54
        //mag_pha1: 0.12, //0.15
    }
}
