"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DescriptorTransformation = void 0;
const transformations_1 = require("@golemio/core/dist/integration-engine/transformations");
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
const RouteTypeEnums_1 = require("../../../../../helpers/RouteTypeEnums");
const VehicleDescriptorEnums_1 = require("../../../../../helpers/VehicleDescriptorEnums");
let DescriptorTransformation = class DescriptorTransformation extends transformations_1.BaseTransformation {
    constructor() {
        super(...arguments);
        this.name = "VPDescriptorTransformation";
        this.transform = (data) => {
            const dto = [];
            for (const dataItem of data) {
                const dtoItem = this.transformElement(dataItem);
                if (dtoItem) {
                    dto.push(dtoItem);
                }
            }
            return Promise.resolve(dto);
        };
        this.transformElement = (dataItem) => {
            return {
                id: dataItem.id,
                state: dataItem.state,
                registration_number: parseInt(dataItem.number),
                registration_number_index: dataItem.numberIndex,
                license_plate: dataItem.plate,
                operator: dataItem.operator,
                manufacturer: dataItem.manufacturer,
                type: dataItem.type,
                traction: dataItem.traction,
                gtfs_route_type: this.mapTractionToRouteType(dataItem.traction),
                is_wheelchair_accessible: typeof dataItem.lowFloor === "number" ? !!dataItem.lowFloor : null,
                is_air_conditioned: !!dataItem.airCondition,
                has_usb_chargers: !!dataItem.usbChargers,
                paint: dataItem.paint,
                thumbnail_url: dataItem.thumbnailUrl?.length === 0 ? null : dataItem.thumbnailUrl,
                photo_url: dataItem.photoUrl?.length === 0 ? null : dataItem.photoUrl,
            };
        };
        this.mapTractionToRouteType = (traction) => {
            switch (traction) {
                case VehicleDescriptorEnums_1.VehicleDescriptorTractionEnum.Bus:
                    return RouteTypeEnums_1.GTFSRouteTypeEnum.BUS;
                case VehicleDescriptorEnums_1.VehicleDescriptorTractionEnum.ElectricBus:
                    return RouteTypeEnums_1.GTFSRouteTypeEnum.BUS;
                case VehicleDescriptorEnums_1.VehicleDescriptorTractionEnum.TrolleyBus:
                    return RouteTypeEnums_1.GTFSRouteTypeEnum.TROLLEYBUS;
                case VehicleDescriptorEnums_1.VehicleDescriptorTractionEnum.Tram:
                    return RouteTypeEnums_1.GTFSRouteTypeEnum.TRAM;
                default:
                    throw new golemio_errors_1.GeneralError(`${this.name}: unknown traction: ${traction}`, this.constructor.name);
            }
        };
    }
};
exports.DescriptorTransformation = DescriptorTransformation;
exports.DescriptorTransformation = DescriptorTransformation = __decorate([
    (0, tsyringe_1.injectable)()
], DescriptorTransformation);
//# sourceMappingURL=DescriptorTransformation.js.map