-- pg_orrery 0.10.0 -> 0.11.0 migration
--
-- Adds make_orbital_elements() constructors and
-- geocentric equatorial functions for planetary moons.

-- ============================================================
-- orbital_elements constructors
-- ============================================================

CREATE FUNCTION make_orbital_elements(
    epoch_jd float8, q_au float8, e float8,
    inc_rad float8, omega_rad float8, node_rad float8,
    tp_jd float8, h_mag float8, g_slope float8
) RETURNS orbital_elements
    AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION make_orbital_elements(float8,float8,float8,float8,float8,float8,float8,float8,float8) IS
    'Construct orbital_elements from 9 floats (angular elements in radians).';

CREATE FUNCTION make_orbital_elements_deg(
    epoch_jd float8, q_au float8, e float8,
    inc_deg float8, omega_deg float8, node_deg float8,
    tp_jd float8, h_mag float8, g_slope float8
) RETURNS orbital_elements
    AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION make_orbital_elements_deg(float8,float8,float8,float8,float8,float8,float8,float8,float8) IS
    'Construct orbital_elements from 9 floats (angular elements in degrees). Matches text I/O and most catalog column layouts.';


-- ============================================================
-- Planetary moon equatorial functions
-- ============================================================

CREATE FUNCTION galilean_equatorial(int4, timestamptz) RETURNS equatorial
    AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION galilean_equatorial(int4, timestamptz) IS
    'Geocentric RA/Dec of a Galilean moon (0=Io, 1=Europa, 2=Ganymede, 3=Callisto). L1.2 theory + VSOP87.';

CREATE FUNCTION saturn_moon_equatorial(int4, timestamptz) RETURNS equatorial
    AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION saturn_moon_equatorial(int4, timestamptz) IS
    'Geocentric RA/Dec of a Saturn moon (0=Mimas..7=Hyperion). TASS17 theory + VSOP87.';

CREATE FUNCTION uranus_moon_equatorial(int4, timestamptz) RETURNS equatorial
    AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION uranus_moon_equatorial(int4, timestamptz) IS
    'Geocentric RA/Dec of a Uranus moon (0=Miranda..4=Oberon). GUST86 theory + VSOP87.';

CREATE FUNCTION mars_moon_equatorial(int4, timestamptz) RETURNS equatorial
    AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION mars_moon_equatorial(int4, timestamptz) IS
    'Geocentric RA/Dec of a Mars moon (0=Phobos, 1=Deimos). MarsSat theory + VSOP87.';
