import { type AeroflyFlight, type AeroflyNavRouteBase, AeroflyNavRouteDepartureRunway, AeroflyNavRouteDestination, AeroflyNavRouteDestinationRunway, AeroflyNavRouteOrigin, AeroflyNavRouteWaypoint, } from "@fboes/aerofly-custom-missions"; import { getFlightplanDestinationCode, getFlightplanDestinationName, getFlightplanOriginCode, getFlightplanOriginName, } from "../../formatter/AeroflyFlightFormatter.js"; export type ExportFileConverterWaypointType = "airport" | "runway" | "navaid" | "waypoint"; export abstract class AeroflyFlightToStringConverter { // static readonly fileExtension: string; abstract convert(flightplan: AeroflyFlight): string; getFlightplanTitle(flightplan: AeroflyFlight): string { return ( flightplan._missionTitle || `Flightplan ${getFlightplanOriginCode(flightplan)} → ${getFlightplanDestinationCode(flightplan)}` ); } getMissionBriefing(flightplan: AeroflyFlight) { return ( flightplan._missionBriefing || `Flight from ${getFlightplanOriginName(flightplan)} to ${getFlightplanDestinationName(flightplan)}.` ); } /** * * @param {AeroflyNavRouteBase} wp Waypoint to get altitude / elevation from * @returns {number | null} altitude / elevation in meters */ protected getWaypointAltitude(wp: AeroflyNavRouteBase): number | null { if (wp instanceof AeroflyNavRouteWaypoint) { return wp.altitude; } else if ( wp instanceof AeroflyNavRouteOrigin || wp instanceof AeroflyNavRouteDepartureRunway || wp instanceof AeroflyNavRouteDestinationRunway || wp instanceof AeroflyNavRouteDestination ) { return wp.elevation; } return null; } protected getWaypointAltitudeFt(wp: AeroflyNavRouteBase): number | null { if (wp instanceof AeroflyNavRouteWaypoint) { return wp.altitude_ft; } else if ( wp instanceof AeroflyNavRouteOrigin || wp instanceof AeroflyNavRouteDepartureRunway || wp instanceof AeroflyNavRouteDestinationRunway || wp instanceof AeroflyNavRouteDestination ) { return wp.elevation_ft; } return null; } protected getWaypointSimplifiedType(wp: AeroflyNavRouteBase): ExportFileConverterWaypointType { switch (wp.constructor) { case AeroflyNavRouteOrigin: case AeroflyNavRouteDestination: return "airport"; case AeroflyNavRouteDepartureRunway: case AeroflyNavRouteDestinationRunway: return "runway"; default: return wp instanceof AeroflyNavRouteWaypoint && wp.navaidFrequency ? "navaid" : "waypoint"; } } }