//! Orbit propagation: SGP4, SDP4, and the free category pipeline.
//!
//! This module implements the SGP4 algorithm for near-earth satellites and
//! provides a stub for SDP4 (deep-space).  The propagation pipeline is
//! modeled as a free category using comp-cat-rs's `Graph`/`Path`/`interpret`.

pub mod classify;
pub mod constants;
pub mod pipeline;
pub mod sdp4;
pub mod sgp4;

use crate::error::Error;
use crate::tle::Tle;
use crate::tle::newtypes::MinutesSinceEpoch;

pub use sgp4::{EciOutput, SgpInit};

/// Propagate a satellite to `tsince` minutes after its TLE epoch.
///
/// Automatically selects SGP4 (near-earth) or SDP4 (deep-space) based
/// on the orbital period.
///
/// # Errors
///
/// Returns an error if initialization or propagation fails.
pub fn propagate(tle: &Tle, tsince: MinutesSinceEpoch) -> Result<EciOutput, Error> {
    let init = SgpInit::from_tle(tle)?;
    match classify::select_propagator(tle.mean_motion()) {
        classify::PropagatorKind::Sgp4 => sgp4::propagate(&init, tsince),
        classify::PropagatorKind::Sdp4 => sdp4::propagate(&init, tsince),
    }
}
