'use strict';

var express = require('express');
var setUpActiveReport = require('../../../middleware/setUpActiveReport.js');
var localsHelper = require('../../../utils/localsHelper.js');
var UserReports = require('../../../types/UserReports.js');
var controller = require('./controller.js');
var routes = require('./sync/routes.js');
var routes$1 = require('./async/routes.js');
var urlHelper = require('../../../utils/urlHelper.js');

/* eslint-disable no-param-reassign */
function Routes({ layoutPath, services }) {
    const router = express.Router({ mergeParams: true });
    const controller$1 = new controller.ViewReportController(layoutPath, services);
    // -------------------
    // SYNC
    // -------------------
    router.use(`/sync/:type/:reportId/:id`, setUpActiveReport.storeActiveReportSessionData({ services, loadType: UserReports.LoadType.SYNC }), routes.default({ layoutPath, services }), controller$1.errorHandler);
    // -------------------
    // ASYNC
    // -------------------
    router.use(`/async/:type/:reportId/:id/:tableId`, setUpActiveReport.storeActiveReportSessionData({ services }), routes$1.default({ layoutPath, services }), controller$1.errorHandler);
    return router;
}
function Redirects() {
    const router = express.Router({ mergeParams: true });
    // View Report
    router.get([`/async/:type/:reportId/:id/request/:tableId/:type`], (req, res) => {
        const { type, reportId, id, tableId } = req.params;
        const { nestedBaseUrl } = localsHelper.getRouteLocals(res);
        const path = urlHelper.setNestedPath(`/dpr/view-report/async/${type}/${reportId}/${id}/${tableId}/${type}`, nestedBaseUrl);
        res.redirect(path);
    });
    // Download
    router.get(`/async/:type/:reportId/:id/request/:tableId/report/:download`, (req, res) => {
        const { type, reportId, id, tableId } = req.params;
        const { nestedBaseUrl } = localsHelper.getRouteLocals(res);
        const path = urlHelper.setNestedPath(`/dpr/view-report/async/${type}/${reportId}/${id}/${tableId}/${type}`, nestedBaseUrl);
        res.redirect(path);
    });
    // Expired Status
    router.post('/async/:type/:reportId/:id/request/:tableId/:type', (req, res) => {
        const { type, reportId, id, tableId } = req.params;
        const { nestedBaseUrl } = localsHelper.getRouteLocals(res);
        const path = urlHelper.setNestedPath(`/dpr/view-report/async/${type}/${reportId}/${id}/${tableId}/${type}`, nestedBaseUrl);
        res.redirect(308, path);
    });
    return router;
}
const ViewReportRoutes = ({ services, path, layoutPath, }) => {
    const router = express.Router({ mergeParams: true });
    router.use(path, Routes({ services, layoutPath }));
    router.use('/', Redirects());
    return router;
};

exports.Redirects = Redirects;
exports.Routes = Routes;
exports.ViewReportRoutes = ViewReportRoutes;
//# sourceMappingURL=routes.js.map
