"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); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var V2DepartureBoardsMinimalController_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.V2DepartureBoardsMinimalController = void 0;
const OgPidToken_1 = require("../../ioc/OgPidToken");
const StopFacade_1 = require("../../service/facade/StopFacade");
const TransferFacade_1 = require("../../service/facade/TransferFacade");
const express_validator_1 = require("@golemio/core/dist/shared/express-validator");
const moment_timezone_1 = __importDefault(require("@golemio/core/dist/shared/moment-timezone"));
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
let V2DepartureBoardsMinimalController = V2DepartureBoardsMinimalController_1 = class V2DepartureBoardsMinimalController {
    constructor(stopFacade, transferFacade) {
        this.stopFacade = stopFacade;
        this.transferFacade = transferFacade;
        this.getDeparturesByCisId = async (req, res, next) => {
            try {
                const queryData = (0, express_validator_1.matchedData)(req);
                const cisIds = Array.isArray(queryData.cisIds) ? queryData.cisIds : [queryData.cisIds];
                const stopIdsLists = await Promise.all(cisIds.map((c) => this.stopFacade.getStopIdsForTransferBoardsByCisId(c)));
                const stopIds = new Set(stopIdsLists.flat());
                if (stopIds.size === 0) {
                    return res.status(404).json({ departures: [] });
                }
                const departures = await this.transferFacade.getDepartureBoards(Array.from(stopIds), (0, moment_timezone_1.default)(), V2DepartureBoardsMinimalController_1.MINUTES_AFTER);
                return res.status(200).json({ departures });
            }
            catch (err) {
                next(err);
            }
        };
    }
};
exports.V2DepartureBoardsMinimalController = V2DepartureBoardsMinimalController;
V2DepartureBoardsMinimalController.MINUTES_AFTER = 30;
exports.V2DepartureBoardsMinimalController = V2DepartureBoardsMinimalController = V2DepartureBoardsMinimalController_1 = __decorate([
    (0, tsyringe_1.injectable)(),
    __param(0, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.StopFacade)),
    __param(1, (0, tsyringe_1.inject)(OgPidToken_1.OgPidToken.TransferFacade)),
    __metadata("design:paramtypes", [StopFacade_1.StopFacade,
        TransferFacade_1.TransferFacade])
], V2DepartureBoardsMinimalController);
//# sourceMappingURL=V2DepartureBoardsMinimalController.js.map