import { TrainSchedule } from './entities/train-schedule.entity'; export type TrainRunSource = Pick; /** * How a departure is named in every customer-facing SMS / email: * * "train 8001 (voyage V-2026-117)" * * Both identifiers are the SCHEDULE's own columns — `train_schedules.train_number` * and `train_schedules.voyage_number`. The built train (`freight.trains`) carries * a `train_name` that the build form labels "voyage number"; that is a different * identifier and must never be quoted to customers. Always pass the schedule. * * Returns null when the schedule has neither number (older rows, or an unbuilt * departure whose pool number is assigned at dispatch) so callers can fall back * to a generic phrase instead of printing "train (voyage)". */ export function trainRunLabel( schedule: TrainRunSource | null | undefined, opts: { capitalize?: boolean } = {}, ): string | null { if (!schedule) return null; const train = schedule.trainNumber?.trim() || null; const voyage = schedule.voyageNumber?.trim() || null; if (!train && !voyage) return null; const head = train ? `train ${train}` : 'train'; const label = voyage ? `${head} (voyage ${voyage})` : head; return opts.capitalize ? label.charAt(0).toUpperCase() + label.slice(1) : label; }