'use strict';

var express = require('express');
var node = require('@sentry/node');
var setUpActiveReport = require('../../../middleware/setUpActiveReport.js');
var controller = require('./controller.js');
var routes = require('./filters/routes.js');
var routes$1 = require('./status/routes.js');
var reportAuthoriser = require('../../../middleware/reportAuthoriser.js');

/* eslint-disable no-param-reassign */
function Routes({ layoutPath, services }) {
    const router = express.Router({ mergeParams: true });
    const controller$1 = new controller.RequestReportController(layoutPath, services);
    router.post(`/:type/:reportId/:id/:executionId/cancel`, controller$1.CANCEL);
    router.use(`/:type/:reportId/:id/filters`, reportAuthoriser.default(services, layoutPath), setUpActiveReport.storeActiveReportSessionData({ services }), routes.default({ layoutPath, services }), controller$1.errorHandler);
    router.use(`/:type/:reportId/:id/:executionId/status`, reportAuthoriser.default(services, layoutPath), setUpActiveReport.storeActiveReportSessionData({ services }), routes$1.default({ layoutPath, services }), controller$1.errorHandler);
    router.get(`/:type/:reportId/:id/:executionId/cancel/failed`, (req, res, _next) => {
        const body = JSON.parse(req.flash('ERROR_BODY')?.[0] || '');
        const params = JSON.parse(req.flash('ERROR_PARAMS')?.[0] || '');
        const error = req.flash('ERROR');
        node.captureException(error);
        res.render(`dpr/routes/journeys/view-report/error`, {
            layoutPath,
            ...(body && { ...body }),
            ...(params && { ...params }),
            error,
            params,
        });
    });
    return router;
}
const RequestReportRoutes = ({ services, path, layoutPath, }) => {
    const router = express.Router({ mergeParams: true });
    router.use(path, Routes({ services, layoutPath }));
    return router;
};

exports.RequestReportRoutes = RequestReportRoutes;
exports.Routes = Routes;
//# sourceMappingURL=routes.js.map
