"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransferBoardSorter = void 0;
const RouteTypeEnums_1 = require("../../../helpers/RouteTypeEnums");
class TransferBoardSorter {
    static sortDepartures(departures) {
        departures.sort((a, b) => {
            for (const compareFn of this.compareFnPipeline) {
                const res = compareFn(a, b);
                if (res !== 0)
                    return res;
            }
            return 0;
        });
    }
}
exports.TransferBoardSorter = TransferBoardSorter;
_a = TransferBoardSorter;
TransferBoardSorter.compareFns = {
    metroFirst: (a, b) => {
        const aIsMetro = a.departure.route_type === RouteTypeEnums_1.GTFSRouteTypeEnum.METRO;
        const bIsMetro = b.departure.route_type === RouteTypeEnums_1.GTFSRouteTypeEnum.METRO;
        if (aIsMetro !== bIsMetro)
            return aIsMetro ? -1 : 1;
        return 0;
    },
    metroNameAsc: (a, b) => {
        const aIsMetro = a.departure.route_type === RouteTypeEnums_1.GTFSRouteTypeEnum.METRO;
        const bIsMetro = b.departure.route_type === RouteTypeEnums_1.GTFSRouteTypeEnum.METRO;
        if (aIsMetro && bIsMetro && a.departure.route_short_name !== null && b.departure.route_short_name !== null)
            return a.departure.route_short_name.localeCompare(b.departure.route_short_name);
        return 0;
    },
    departureTimeAsc: (a, b) => {
        const aTimestamp = a.departure.predictedDepartureTimestamp;
        const bTimestamp = b.departure.predictedDepartureTimestamp;
        if (aTimestamp && bTimestamp) {
            return aTimestamp - bTimestamp;
        }
        if (!aTimestamp && !bTimestamp)
            return 0;
        if (!bTimestamp)
            return -1;
        return 1;
    },
    directionIdAsc: (a, b) => {
        const aDirectionId = a.position?.detailed_info.direction_id;
        const bDirectionId = b.position?.detailed_info.direction_id;
        if (aDirectionId !== bDirectionId)
            return aDirectionId ? -1 : 1;
        return 0;
    },
};
TransferBoardSorter.compareFnPipeline = [
    _a.compareFns.metroFirst,
    _a.compareFns.metroNameAsc,
    _a.compareFns.departureTimeAsc,
    _a.compareFns.directionIdAsc,
];
//# sourceMappingURL=TransferBoardSorter.js.map