"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.v2PublicDeparturesRouter = exports.V2PublicDeparturesRouter = void 0;
const V2PublicDepartureBoardsController_1 = require("../../controllers/v2/V2PublicDepartureBoardsController");
const Di_1 = require("../../ioc/Di");
const OgModuleToken_1 = require("../../ioc/OgModuleToken");
const constants_1 = require("../../../shared/constants");
const AbstractRouter_1 = require("@golemio/core/dist/helpers/routing/AbstractRouter");
const Validation_1 = require("@golemio/core/dist/output-gateway/Validation");
const ioc_1 = require("@golemio/core/dist/output-gateway/ioc");
const express_1 = require("@golemio/core/dist/shared/express");
const express_validator_1 = require("@golemio/core/dist/shared/express-validator");
const CustomStopIdGroupValidator_1 = require("./helpers/CustomStopIdGroupValidator");
class V2PublicDeparturesRouter extends AbstractRouter_1.AbstractRouter {
    constructor() {
        super(constants_1.RouteVersion.v2, "public/departureboards");
        this.router = (0, express_1.Router)();
        this.cacheHeaderMiddleware = Di_1.OgPublicContainer.resolve(ioc_1.ContainerToken.CacheHeaderMiddleware);
        this.compressionByDefaultMiddleware = Di_1.OgPublicContainer.resolve(ioc_1.ContainerToken.CompressionByDefaultMiddleware);
        this.departureController = new V2PublicDepartureBoardsController_1.V2PublicDepartureBoardsController();
        this.gtfsStopsSubscriber = Di_1.OgPublicContainer.resolve(OgModuleToken_1.OgModuleToken.GtfsStopsSubscriber);
        this.gtfsStopsSubscriber.initialize();
        this.initRoutes();
    }
    initRoutes() {
        this.router.get("/", [
            (0, express_validator_1.query)("stopIds").exists().custom(CustomStopIdGroupValidator_1.CustomStopIdGroupValidator.validate),
            (0, express_validator_1.query)("limit").optional().isInt({ min: 1, max: 30 }).not().isArray(),
            (0, express_validator_1.query)("routeShortNames").optional().not().isEmpty({ ignore_whitespace: true }),
            (0, express_validator_1.query)("minutesAfter").optional().isInt({ min: 1, max: 360 }).not().isArray(),
            (0, express_validator_1.query)("minutesBefore").optional().isInt({ min: -359, max: 30 }).not().isArray(),
        ], Validation_1.checkErrors, 
        // max-age 3 seconds, stale-while-revalidate 2 seconds
        this.cacheHeaderMiddleware.getMiddleware(3, 2), this.compressionByDefaultMiddleware.getMiddleware(), this.departureController.getAll);
    }
}
exports.V2PublicDeparturesRouter = V2PublicDeparturesRouter;
const v2PublicDeparturesRouter = new V2PublicDeparturesRouter();
exports.v2PublicDeparturesRouter = v2PublicDeparturesRouter;
//# sourceMappingURL=V2PublicDeparturesRouter.js.map