// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 Vallés Puig, Ramon

//! # Stellar Azimuth
//!
//! Fixed-star azimuth scalar function, used by the unified azimuth calculus
//! API via the [`AzimuthProvider`](crate::event::azimuth::AzimuthProvider) trait.

use crate::astro::apparent::CorrectionPolicy;
use crate::coordinates::centers::Geodetic;
use crate::coordinates::frames::ECEF;
use crate::qtty::*;
use crate::time::{JulianDate, ModifiedJulianDate};

/// Computes the topocentric azimuth of a fixed star in **radians**
/// (North-clockwise, range `[0, 2π)`) at a given Julian Date and observer site.
///
/// Uses IAU 2006 precession + IAU 2000B nutation (via NPB matrix), ERA-based
/// GAST, and the standard equatorial→horizontal formula.
///
/// # Arguments
/// * `mjd`      , Modified Julian Date (TT)
/// * `site`     , Observer's geographic location
/// * `ra_j2000` , Right Ascension (J2000), in degrees
/// * `dec_j2000`, Declination (J2000), in degrees
pub(crate) fn fixed_star_azimuth_rad(
    mjd: ModifiedJulianDate,
    site: &Geodetic<ECEF>,
    ra_j2000: Degrees,
    dec_j2000: Degrees,
) -> Radians {
    fixed_star_azimuth_rad_with_policy(mjd, site, ra_j2000, dec_j2000, CorrectionPolicy::APPARENT)
}

/// Computes fixed-star azimuth with an explicit apparent-position policy.
pub(crate) fn fixed_star_azimuth_rad_with_policy(
    mjd: ModifiedJulianDate,
    site: &Geodetic<ECEF>,
    ra_j2000: Degrees,
    dec_j2000: Degrees,
    policy: CorrectionPolicy,
) -> Radians {
    let jd: JulianDate = mjd.to::<crate::JD>();
    crate::event::horizontal::star_horizontal_with_policy(ra_j2000, dec_j2000, site, jd, policy)
        .az()
        .to::<Radian>()
}
