"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VehicleDescriptorTripScopeHandler = void 0;
const RouteTypeEnums_1 = require("../../../../../../helpers/RouteTypeEnums");
const VehicleDescriptorCachedRepository_1 = require("../../../../data-access/VehicleDescriptorCachedRepository");
const OgModuleToken_1 = require("../../../../ioc/OgModuleToken");
const PublicVPVehicleDescriptorTransformation_1 = require("../../../transformations/scopes/PublicVPVehicleDescriptorTransformation");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
const AbstractDetailedTripScopeHandler_1 = require("./AbstractDetailedTripScopeHandler");
let VehicleDescriptorTripScopeHandler = class VehicleDescriptorTripScopeHandler extends AbstractDetailedTripScopeHandler_1.AbstractDetailedTripScopeHandler {
    constructor(vehicleDescriptorRepository) {
        super();
        this.vehicleDescriptorRepository = vehicleDescriptorRepository;
        this.vehicleDescriptorTransformation = new PublicVPVehicleDescriptorTransformation_1.PublicVPVehicleDescriptorTransformation();
    }
    async handle(output, vehiclePosition) {
        output.vehicle_descriptor = this.vehicleDescriptorTransformation.transformElement(vehiclePosition);
        const registrationNumber = vehiclePosition.detailed_info.registration_number;
        if (registrationNumber) {
            const routeType = vehiclePosition.route_type;
            const descriptor = await this.vehicleDescriptorRepository.getOneByRegNumber(routeType, registrationNumber);
            if (!descriptor) {
                return output;
            }
            output.vehicle_descriptor = {
                ...output.vehicle_descriptor,
                vehicle_type: this.getVehicleType(descriptor, vehiclePosition),
                is_air_conditioned: descriptor.is_air_conditioned,
                has_usb_chargers: descriptor.has_usb_chargers,
            };
        }
        return output;
    }
    getVehicleType(descriptor, vehiclePosition) {
        const date = new Date();
        // getMonth() returns 0-based index, unlike getDate()
        if (date.getDate() === 1 && date.getMonth() === 3) {
            return this.getAprilVehicleType(descriptor, vehiclePosition);
        }
        return `${descriptor.manufacturer} ${descriptor.type}`;
    }
    getAprilVehicleType(descriptor, vehiclePosition) {
        switch (vehiclePosition.route_type) {
            case RouteTypeEnums_1.GTFSRouteTypeEnum.TRAM:
                switch (descriptor.type) {
                    case "T3R.P":
                    case "T3R.PLF":
                    case "T3R.PV":
                    case "T3M.2":
                        return "Mašinka Tomáš";
                    case "KT8D5.RN2P":
                        return "Orient Express";
                    case "14T":
                        return "Polární expres";
                    case "15T1":
                    case "15T2":
                    case "15T3":
                    case "15T4":
                    case "15T5":
                    case "15T6":
                    case "15T7":
                        return "Snowpiercer";
                    default:
                        return "Trainy McTrainface";
                }
            case RouteTypeEnums_1.GTFSRouteTypeEnum.METRO:
            case RouteTypeEnums_1.GTFSRouteTypeEnum.TRAIN:
                return "Trainy McTrainface";
            case RouteTypeEnums_1.GTFSRouteTypeEnum.BUS:
                switch (descriptor.manufacturer) {
                    case "Iveco":
                        return "Batmobile";
                    case "SOR":
                        return "Ectomobile";
                    case "Setra":
                        return "KITT";
                    case "Otokar":
                        return "Formule";
                    case "Irisbus":
                        return "DeLorean time machine";
                    case "Scania":
                        return "Mr. Slowly";
                    case "MAN":
                        return "Tatra T815 aka The War Rig";
                    case "Solaris":
                        return "Citroën DS Fantomas";
                    case "ROŠERO - P":
                        return "The Mystery Machine";
                    default:
                        return "Bussy McBusface";
                }
            case RouteTypeEnums_1.GTFSRouteTypeEnum.FERRY:
                return "RMS Titanic";
            case RouteTypeEnums_1.GTFSRouteTypeEnum.TROLLEYBUS:
                switch (descriptor.manufacturer) {
                    case "Škoda-Solaris":
                        return "Lightning McQueen";
                    default:
                        return "Bussy McBusface";
                }
            default:
                return `${descriptor.manufacturer} ${descriptor.type}`;
        }
    }
};
exports.VehicleDescriptorTripScopeHandler = VehicleDescriptorTripScopeHandler;
exports.VehicleDescriptorTripScopeHandler = VehicleDescriptorTripScopeHandler = __decorate([
    (0, tsyringe_1.injectable)(),
    __param(0, (0, tsyringe_1.inject)(OgModuleToken_1.OgModuleToken.VehicleDescriptorCachedRepository)),
    __metadata("design:paramtypes", [VehicleDescriptorCachedRepository_1.VehicleDescriptorCachedRepository])
], VehicleDescriptorTripScopeHandler);
//# sourceMappingURL=VehicleDescriptorTripScopeHandler.js.map