import { Router } from 'express';
import { storeActiveReportSessionData } from '../../../middleware/setUpActiveReport.js';
import { getRouteLocals } from '../../../utils/localsHelper.js';
import { LoadType } from '../../../types/UserReports.js';
import { ViewReportController } from './controller.js';
import routes from './sync/routes.js';
import routes$1 from './async/routes.js';
import { setNestedPath } from '../../../utils/urlHelper.js';

/* eslint-disable no-param-reassign */
function Routes({ layoutPath, services }) {
    const router = Router({ mergeParams: true });
    const controller = new ViewReportController(layoutPath, services);
    // -------------------
    // SYNC
    // -------------------
    router.use(`/sync/:type/:reportId/:id`, storeActiveReportSessionData({ services, loadType: LoadType.SYNC }), routes({ layoutPath, services }), controller.errorHandler);
    // -------------------
    // ASYNC
    // -------------------
    router.use(`/async/:type/:reportId/:id/:tableId`, storeActiveReportSessionData({ services }), routes$1({ layoutPath, services }), controller.errorHandler);
    return router;
}
function Redirects() {
    const router = 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 } = getRouteLocals(res);
        const path = 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 } = getRouteLocals(res);
        const path = 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 } = getRouteLocals(res);
        const path = setNestedPath(`/dpr/view-report/async/${type}/${reportId}/${id}/${tableId}/${type}`, nestedBaseUrl);
        res.redirect(308, path);
    });
    return router;
}
const ViewReportRoutes = ({ services, path, layoutPath, }) => {
    const router = Router({ mergeParams: true });
    router.use(path, Routes({ services, layoutPath }));
    router.use('/', Redirects());
    return router;
};

export { Redirects, Routes, ViewReportRoutes };
//# sourceMappingURL=routes.js.map
