"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FilterHelper = void 0;
const DepartureFilter_1 = require("../../helpers/enums/DepartureFilter");
class FilterHelper {
    static routeOnceHeadingCondition(accumulator, currentDeparture) {
        // only the first departure to respone for trips with same route_id and heading
        return !FilterHelper.isInOnceBucketWithHeading(accumulator, currentDeparture);
    }
    static routeOnceHeadingNoGapCondition(accumulator, currentDeparture) {
        // extension of routeOnceHeading filter, when we skip some route_id afterwards it doesnt show up even different headings
        return (!FilterHelper.isInOnceBucketWithHeadingWithPlatform(accumulator, currentDeparture) &&
            !FilterHelper.isInFillBucket(accumulator, currentDeparture));
    }
    static routeOnceCondition(accumulator, currentDeparture) {
        // only the first departure to respone for trips with same route_id
        return !FilterHelper.isInOnceBucket(accumulator, currentDeparture);
    }
    static isFillFilterType(filter) {
        return (filter === DepartureFilter_1.DepartureFilter.ROUTE_ONCE_FILL ||
            filter === DepartureFilter_1.DepartureFilter.ROUTE_HEADING_ONCE_FILL ||
            filter === DepartureFilter_1.DepartureFilter.ROUTE_HEADING_ONCE_NOGAP_FILL);
    }
    static isInFillBucket(accumulator, currentDeparture) {
        return accumulator.fill.some((e) => FilterHelper.sameRouteId(e, currentDeparture) && FilterHelper.samePlatformCode(e, currentDeparture));
    }
    static isInOnceBucketWithHeading(accumulator, currentDeparture) {
        return accumulator.once.some((e) => FilterHelper.sameRouteId(e, currentDeparture) && FilterHelper.sameHeadsign(e, currentDeparture));
    }
    static isInOnceBucketWithHeadingWithPlatform(accumulator, currentDeparture) {
        return accumulator.once.some((e) => FilterHelper.sameRouteId(e, currentDeparture) &&
            FilterHelper.sameHeadsign(e, currentDeparture) &&
            FilterHelper.samePlatformCode(e, currentDeparture));
    }
    static sameProperty(a, b, property) {
        return a[property] === b[property];
    }
    static sameRouteId(a, b) {
        return FilterHelper.sameProperty(a, b, FilterHelper.routeId);
    }
    static sameHeadsign(a, b) {
        return FilterHelper.sameProperty(a, b, b.stop_headsign ? FilterHelper.stopHeadsign : FilterHelper.tripHeadsign);
    }
    static samePlatformCode(a, b) {
        return FilterHelper.sameProperty(a, b, b[FilterHelper.tripCisStopPlatformCode] ? FilterHelper.tripCisStopPlatformCode : FilterHelper.platformCode);
    }
    static isInOnceBucket(accumulator, currentDeparture) {
        return accumulator.once.findIndex((e) => e.route_id === currentDeparture.route_id) >= 0;
    }
}
exports.FilterHelper = FilterHelper;
FilterHelper.routeId = "route_id";
FilterHelper.platformCode = "platform_code";
FilterHelper.tripCisStopPlatformCode = "trip.cis_stop_platform_code";
FilterHelper.stopHeadsign = "stop_headsign";
FilterHelper.tripHeadsign = "trip_headsign";
//# sourceMappingURL=FilterHelper.js.map