"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.vehiclePositionsRouter = exports.VehiclePositionsRouter = void 0;
const helpers_1 = require("@golemio/core/dist/input-gateway/helpers");
const express_1 = require("@golemio/core/dist/shared/express");
const VehiclePositionsController_1 = require("./VehiclePositionsController");
const AbstractRouter_1 = require("@golemio/core/dist/helpers/routing/AbstractRouter");
class VehiclePositionsRouter extends AbstractRouter_1.AbstractRouter {
    constructor() {
        super("v1", "vehiclepositions");
        /**
         * Initiates all routes. Should respond with correct data to a HTTP requests to all routes.
         */
        this.initRoutes = () => {
            this.router.post("/", (0, helpers_1.checkContentTypeMiddleware)(["text/xml"]), this.Post);
        };
        this.Post = async (req, res, next) => {
            try {
                await this.controller.processData(req.body);
                // logging number of records
                const dataToEmit = {
                    numberOfRecords: req.body && req.body.m && req.body.m.spoj && req.body.m.spoj instanceof Array
                        ? req.body.m.spoj.length
                        : req.body && req.body.m && req.body.m.spoj
                            ? 1
                            : 0,
                    req,
                };
                helpers_1.loggerEvents.emit(helpers_1.LoggerEventType.NumberOfRecords, dataToEmit);
                res.sendStatus(204);
            }
            catch (err) {
                next(err);
            }
        };
        this.router = (0, express_1.Router)();
        this.controller = new VehiclePositionsController_1.VehiclePositionsController();
        this.initRoutes();
    }
}
exports.VehiclePositionsRouter = VehiclePositionsRouter;
const vehiclePositionsRouter = new VehiclePositionsRouter();
exports.vehiclePositionsRouter = vehiclePositionsRouter;
//# sourceMappingURL=VehiclePositionsRouter.js.map