"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlatformCodeResolver = void 0;
const RouteTypeEnums_1 = require("../../helpers/RouteTypeEnums");
class PlatformCodeResolver {
    /**
     * Platform code is determined by the following rules:
     *  - for trains, the last stop platform code is used (CIS) if available
     *    - otherwise, the departure platform code is used (GTFS)
     *  - for other route types, the departure platform code is used (GTFS)
     * @param departure Must have `route_type` and `platform_code` properties
     * @param cisStopPlatformCode For trains - this is where the `cis_stop_platform_code` goes
     * @param makeItShort Applies parsing for trains to get shorter platform from 6J/26J => 6J
     */
    static resolveDirect(departure, cisStopPlatformCode, makeItShort = false) {
        const { route_type, platform_code } = departure;
        if (route_type === RouteTypeEnums_1.GTFSRouteTypeEnum.TRAIN && cisStopPlatformCode != null) {
            return makeItShort ? this.shortTrainPlatform(cisStopPlatformCode) : cisStopPlatformCode;
        }
        return platform_code;
    }
    /**
     * Determine platform code based on the following rules:
     *   if current stop time is known, use its RT CIS platform code (if available)
     *   otherwise use GTFS schedule platform code
     */
    static fromStopTimeCisShort(departure, stopTime) {
        return PlatformCodeResolver.resolveDirect(departure, stopTime?.cis_stop_platform_code ?? null, true);
    }
    static shortTrainPlatform(platformCode) {
        return (platformCode.match(PlatformCodeResolver.shortPlatformRegex) ?? [platformCode])[0];
    }
}
exports.PlatformCodeResolver = PlatformCodeResolver;
PlatformCodeResolver.shortPlatformRegex = /[^/-]+/g;
//# sourceMappingURL=PlatformCodeResolver.js.map