"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TripScheduleManager = void 0;
const TripScheduleRepository_1 = require("../../../../../ropid-gtfs/data-access/precomputed/TripScheduleRepository");
const sequelize_1 = require("@golemio/core/dist/shared/sequelize");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
let TripScheduleManager = class TripScheduleManager {
    constructor() {
        this.tripScheduleRepository = new TripScheduleRepository_1.TripScheduleRepository();
    }
    async getScheduleInput(message, subAgencyEntities, descriptorEntities) {
        const subAgencyEntity = subAgencyEntities.find((subAgency) => subAgency.route_licence_number && subAgency.route_licence_number.toString() === message.cis_line_id);
        if (!subAgencyEntity) {
            return null;
        }
        const descriptorEntity = descriptorEntities.find((descriptor) => descriptor.registration_number === message.registration_number);
        const gtfsScheduleData = await this.tripScheduleRepository.findOne({
            attributes: ["origin_route_name", "run_number", "trip_id"],
            where: {
                route_licence_number: message.cis_line_id,
                trip_number: message.cis_trip_number,
                [sequelize_1.Op.and]: [sequelize_1.Sequelize.literal("start_timestamp::date = current_date")],
            },
        });
        if (!gtfsScheduleData) {
            return null;
        }
        return {
            cache_lookup_key: `${message.cis_line_id}_${message.cis_trip_number}`,
            route_id: gtfsScheduleData.origin_route_name,
            run_number: gtfsScheduleData.run_number,
            msg_last_timestamp: message.vehicle_timestamp,
            gtfs_trip_id: gtfsScheduleData.trip_id,
            agency_name: subAgencyEntity.sub_agency_name,
            is_wheelchair_accessible: descriptorEntity?.is_wheelchair_accessible ?? null,
        };
    }
};
exports.TripScheduleManager = TripScheduleManager;
exports.TripScheduleManager = TripScheduleManager = __decorate([
    (0, tsyringe_1.injectable)(),
    __metadata("design:paramtypes", [])
], TripScheduleManager);
//# sourceMappingURL=TripScheduleManager.js.map