"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublicDepartureTransformation = void 0;
const RouteTypeEnums_1 = require("../../../../helpers/RouteTypeEnums");
const shared_1 = require("../../../shared");
const RopidRouterUtils_1 = require("../../../shared/RopidRouterUtils");
const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation");
const const_1 = require("../../../../const");
class PublicDepartureTransformation extends AbstractTransformation_1.AbstractTransformation {
    constructor() {
        super(...arguments);
        this.name = "PublicDepartureTransformation";
        this.transformInternal = (inputDto) => {
            const { departure, vehiclePosition, vehicleDescriptor } = inputDto;
            const delayInSeconds = vehiclePosition?.delay ?? null;
            const departureTime = new Date(departure.departure_datetime);
            const arrivalTime = departure.arrival_datetime ? new Date(departure.arrival_datetime) : null;
            const predictedDepartureTime = shared_1.DepartureCalculator.getPredictedDepartureTime(departureTime, arrivalTime, delayInSeconds);
            let vehicle;
            if (vehiclePosition?.state_position === const_1.StatePositionEnum.CANCELED || !vehiclePosition) {
                vehicle = {
                    id: null,
                    is_wheelchair_accessible: null,
                    is_air_conditioned: null,
                    has_charger: null,
                };
            }
            else {
                vehicle = {
                    id: vehiclePosition.vehicle_id ?? null,
                    is_wheelchair_accessible: vehiclePosition.detailed_info.is_wheelchair_accessible ?? null,
                    is_air_conditioned: vehicleDescriptor?.is_air_conditioned ?? null,
                    has_charger: vehicleDescriptor?.has_usb_chargers ?? null,
                };
            }
            return {
                departure: {
                    timestamp_scheduled: RopidRouterUtils_1.RopidRouterUtils.formatTimestamp(departureTime) ?? departure.departure_datetime,
                    timestamp_predicted: RopidRouterUtils_1.RopidRouterUtils.formatTimestamp(predictedDepartureTime) ?? departure.departure_datetime,
                    delay_seconds: delayInSeconds,
                    minutes: shared_1.DepartureCalculator.getDepartureMinutes(predictedDepartureTime),
                },
                stop: {
                    id: departure.stop_id,
                    sequence: departure.stop_sequence,
                    platform_code: shared_1.PlatformCodeResolver.fromStopTimeCisShort(departure, inputDto.stopTime),
                },
                route: {
                    type: RouteTypeEnums_1.GTFSRouteTypeEnum[departure.route_type].toLowerCase(),
                    short_name: departure.route_short_name,
                },
                trip: {
                    id: departure.trip_id,
                    headsign: departure.trip_headsign,
                    is_canceled: vehiclePosition?.state_position === const_1.StatePositionEnum.CANCELED,
                },
                vehicle,
            };
        };
    }
}
exports.PublicDepartureTransformation = PublicDepartureTransformation;
//# sourceMappingURL=PublicDepartureTransformation.js.map