import type { IFlightLegStation } from "../../types.js";

export type StationChange = "city" | "airport" | "terminal" | "noChange";

/**
 * Detect the kind of transition between two stations by priority:
 * city change > airport change > terminal change > no change.
 *
 * Uses the `scheduled` snapshot for comparisons (stable across updates).
 */
export function detectStationChange(
  from: IFlightLegStation,
  to: IFlightLegStation,
): StationChange {
  if (from.scheduled.cityCode !== to.scheduled.cityCode) return "city";
  if (from.scheduled.airportCode !== to.scheduled.airportCode) return "airport";
  if (from.terminal && to.terminal && from.terminal !== to.terminal) return "terminal";
  return "noChange";
}
