mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 09:00:57 +00:00
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { WagonReadiness, type ScheduleTradeDirection } from '@edr/types';
|
|
|
|
export function requiredWagonReadiness(
|
|
direction: ScheduleTradeDirection | string | null | undefined,
|
|
): WagonReadiness | null {
|
|
if (direction === 'IMPORT') return WagonReadiness.ImportReady;
|
|
if (direction === 'EXPORT') return WagonReadiness.ExportReady;
|
|
return null;
|
|
}
|
|
|
|
export function wagonReadinessMatchesSchedule(
|
|
wagonReadiness: WagonReadiness | string,
|
|
direction: ScheduleTradeDirection | string | null | undefined,
|
|
): boolean {
|
|
const required = requiredWagonReadiness(direction);
|
|
if (!required) return true;
|
|
return wagonReadiness === required;
|
|
}
|
|
|
|
/**
|
|
* Toggle a readiness value (IMPORT_READY ↔ EXPORT_READY). Used when a train
|
|
* reaches its destination: the asset has repositioned, so it is now ready for
|
|
* the opposite direction. Direction-agnostic so it handles round trips.
|
|
*/
|
|
export function flipReadiness(
|
|
readiness: WagonReadiness | string,
|
|
): WagonReadiness {
|
|
return readiness === WagonReadiness.ImportReady
|
|
? WagonReadiness.ExportReady
|
|
: WagonReadiness.ImportReady;
|
|
}
|