"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.v4PidRouter = exports.V4PIDRouter = void 0;
const RouteTypeEnums_1 = require("../../../../helpers/RouteTypeEnums");
const ParamValidatorManager_1 = require("../../helpers/ParamValidatorManager");
const Di_1 = require("../../ioc/Di");
const OgPidToken_1 = require("../../ioc/OgPidToken");
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 const_1 = require("../../../../const");
class V4PIDRouter extends AbstractRouter_1.AbstractRouter {
    constructor() {
        super(constants_1.RouteVersion.v4, "pid");
        this.router = (0, express_1.Router)();
        this.initRoutes = () => {
            this.registerTransferBoardsRoutes();
        };
        this.registerTransferBoardsRoutes = () => {
            const transferBoardsValidation = [
                (0, express_validator_1.query)("aswId").optional().custom(ParamValidatorManager_1.ParamValidatorManager.getAswIdsValidator()).not().isArray(),
                (0, express_validator_1.query)("cisId").optional().isInt({ min: const_1.PG_INT_MIN, max: const_1.PG_INT_MAX }).toInt(10).not().isArray(),
                (0, express_validator_1.query)("tripNumber").optional().isInt({ min: 0 }).toInt(10).not().isArray(),
                (0, express_validator_1.query)("vehicleRegistrationNumber").optional().not().isEmpty({ ignore_whitespace: true }).not().isArray(),
                (0, express_validator_1.oneOf)([
                    [
                        (0, express_validator_1.query)("aswId").exists(),
                        (0, express_validator_1.query)("vehicleRegistrationNumber").exists(),
                        (0, express_validator_1.query)("tripNumber").not().exists(),
                        (0, express_validator_1.query)("cisId").not().exists(),
                    ],
                    [
                        (0, express_validator_1.query)("cisId").exists(),
                        (0, express_validator_1.query)("tripNumber").exists(),
                        (0, express_validator_1.query)("aswId").not().exists(),
                        (0, express_validator_1.query)("vehicleRegistrationNumber").not().exists(),
                    ],
                ], {
                    message: "Either an aswId+vehicleRegistrationNumber (and no cisId+tripNumber), " +
                        "or a cisId+tripNumber (and aswId+vehicleRegistrationNumber) must be provided",
                }),
                (0, express_validator_1.query)("routeType").exists().isInt().isIn(Object.values(RouteTypeEnums_1.GTFSRouteTypeEnum)).toInt(10).not().isArray(),
                (0, express_validator_1.query)("timeFrom").optional().isISO8601().custom(ParamValidatorManager_1.ParamValidatorManager.getTimeFromValidator()).not().isArray(),
                (0, express_validator_1.query)("limit").optional().isInt({ min: 1, max: 30 }).toInt(10).not().isArray(),
            ];
            this.router.get("/transferboards", transferBoardsValidation, Validation_1.checkErrors, 
            // max-age 5 seconds, stale-while-revalidate 5 seconds
            this.cacheHeaderMiddleware.getMiddleware(5, 5), this.transferBoardsController.getTransferBoardData);
        };
        this.cacheHeaderMiddleware = ioc_1.OutputGatewayContainer.resolve(ioc_1.ContainerToken.CacheHeaderMiddleware);
        this.transferBoardsController = Di_1.OgPidContainer.resolve(OgPidToken_1.OgPidToken.V4TransferBoardsController);
        this.GtfsStopsSubscriber = Di_1.OgPidContainer.resolve(OgPidToken_1.OgPidToken.GtfsStopsSubscriber);
        this.GtfsStopsSubscriber.initialize();
        this.JisInfotextsSubscriber = Di_1.OgPidContainer.resolve(OgPidToken_1.OgPidToken.JisInfotextsSubscriber);
        this.JisInfotextsSubscriber.initialize();
        this.VPSubscriber = Di_1.OgPidContainer.resolve(OgPidToken_1.OgPidToken.VPSubscriber);
        this.VPSubscriber.initialize();
        this.initRoutes();
    }
}
exports.V4PIDRouter = V4PIDRouter;
const v4PidRouter = new V4PIDRouter();
exports.v4PidRouter = v4PidRouter;
//# sourceMappingURL=V4PIDRouter.js.map