"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ModuleContainerToken_1 = require("../../../../ioc/ModuleContainerToken");
const Di_1 = require("../../../ioc/Di");
class DPPUtils {
    static isOnTheWayFromGarage(originTimestamp, firstSegment, currentCoordinates, firstStopCoordinates) {
        const geoHelper = Di_1.VPContainer.resolve(ModuleContainerToken_1.ModuleContainerToken.GeoMeasurementHelper);
        if (originTimestamp.getTime() < new Date(firstSegment.start_timestamp).valueOf() - this.TIME_THRESHOLD_IN_MS) {
            const distanceFromFirstStop = geoHelper.getDistanceInKilometers(currentCoordinates, firstStopCoordinates);
            return distanceFromFirstStop > this.DISTANCE_THRESHOLD_IN_KM;
        }
        return false;
    }
    static isOnTheWayToGarage(lastSegment, gtfsTripId, isTracked, lastPositionTracking) {
        // if it is last line on the track (gtfstripid is same as last trip id in a schedule for a given day)
        // and the position is not tracked and lastPositioTracking var is not null meaning vehicle was already on track
        return lastSegment.trip_id === gtfsTripId && !isTracked && lastPositionTracking != null;
    }
}
DPPUtils.DPP_AGENCY_NAME = "DP PRAHA";
DPPUtils.TIME_THRESHOLD_IN_MS = 1 * 60 * 1000;
DPPUtils.DISTANCE_THRESHOLD_IN_KM = 0.5;
// Decide DPP trips to set invisible, in cases when vehicle is on the way from or to garage.
DPPUtils.isInvisible = (agencyNameScheduled, originTimestamp, startTimestamp, currentCoordinates, firstStopCoordinates, schedule, gtfsTripId, lastPositionTracking, isTracked) => {
    // For DPP PRAHA we need filter all buses which are not close to first/last stop (.5km)
    // and still not tracking (except those with time in range of theirs trip stop times)
    if (agencyNameScheduled !== DPPUtils.DPP_AGENCY_NAME)
        return false;
    if (!schedule)
        return false;
    const tripDate = schedule.find((el) => new Date(el.start_timestamp).valueOf() == startTimestamp)?.date;
    const tripsForDay = schedule.filter((el) => el.date == tripDate);
    if (tripsForDay.length === 0)
        return false;
    const firstSegment = tripsForDay[0];
    const lastSegment = tripsForDay[tripsForDay.length - 1];
    return (DPPUtils.isOnTheWayFromGarage(originTimestamp, firstSegment, currentCoordinates, firstStopCoordinates) ||
        DPPUtils.isOnTheWayToGarage(lastSegment, gtfsTripId, isTracked, lastPositionTracking));
};
exports.default = DPPUtils;
//# sourceMappingURL=DPPUtils.js.map