"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.GtfsLookupManager = void 0;
const VPContainerToken_1 = require("../../../../ioc/VPContainerToken");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
const RegionalBusGtfsCacheRepository_1 = require("../../data-access/cache/RegionalBusGtfsCacheRepository");
let GtfsLookupManager = class GtfsLookupManager {
    constructor(gtfsLookupCacheRepository) {
        this.gtfsLookupCacheRepository = gtfsLookupCacheRepository;
    }
    async getScheduleInputData(messages) {
        const cacheLookupKeys = messages.map((message) => `${message.cis_line_id}_${message.cis_trip_number}`);
        const gtfsCacheData = await this.gtfsLookupCacheRepository.mget(cacheLookupKeys);
        let scheduleInputData = [];
        for (let i = 0; i < messages.length; i++) {
            const message = messages[i];
            const gtfsCacheItem = gtfsCacheData[i];
            if (!gtfsCacheItem) {
                scheduleInputData.push(null);
                continue;
            }
            scheduleInputData.push({
                route_id: gtfsCacheItem.route_name,
                run_number: gtfsCacheItem.run_number,
                msg_last_timestamp: message.vehicle_timestamp,
                gtfs_trip_id: gtfsCacheItem.gtfs_trip_id,
                agency_name: gtfsCacheItem.agency_name,
                is_wheelchair_accessible: gtfsCacheItem.is_wheelchair_accessible,
            });
        }
        return scheduleInputData;
    }
    async setGtfsScheduleLookup(scheduleInputData) {
        for (const scheduleInputItem of scheduleInputData) {
            const gtfsCacheItem = {
                gtfs_trip_id: scheduleInputItem.gtfs_trip_id,
                route_name: scheduleInputItem.route_id,
                run_number: scheduleInputItem.run_number,
                agency_name: scheduleInputItem.agency_name,
                is_wheelchair_accessible: scheduleInputItem.is_wheelchair_accessible,
            };
            await this.gtfsLookupCacheRepository.set(scheduleInputItem.cache_lookup_key, gtfsCacheItem);
        }
    }
};
exports.GtfsLookupManager = GtfsLookupManager;
exports.GtfsLookupManager = GtfsLookupManager = __decorate([
    (0, tsyringe_1.injectable)(),
    __param(0, (0, tsyringe_1.inject)(VPContainerToken_1.VPContainerToken.RegionalBusGtfsCacheRepository)),
    __metadata("design:paramtypes", [RegionalBusGtfsCacheRepository_1.RegionalBusGtfsCacheRepository])
], GtfsLookupManager);
//# sourceMappingURL=GtfsLookupManager.js.map