import { ErrorHandler } from '../../../../../utils/ErrorHandler/ErrorHandler.js';
import SyncReportUtils from './utils.js';
import { FiltersType } from '../../../../../components/_filters/filtersTypeEnum.js';
import PersonalisationUtils from '../../../../../utils/Personalisation/personalisationUtils.js';
import ViewReportUtils from '../../utils.js';

class ViewSyncReportController {
    layoutPath;
    services;
    constructor(layoutPath, services) {
        this.layoutPath = layoutPath;
        this.services = services;
    }
    GET = async (req, res, next) => {
        try {
            const renderData = await SyncReportUtils.getReport({ req, res, services: this.services });
            res.render(`dpr/routes/journeys/view-report/report`, {
                layoutPath: this.layoutPath,
                ...renderData,
            });
        }
        catch (error) {
            req.body ??= {};
            req.body.title = `Report Failed`;
            req.body.errorDescription = 'We were unable to show this report for the following reason:';
            req.body.error = new ErrorHandler(error).formatError();
            next(error);
        }
    };
    saveDefaultFilterValues = async (req, res, next) => {
        try {
            PersonalisationUtils.saveDefaults(FiltersType.INTERACTIVE, res, req, this.services);
            res.redirect(`${req.baseUrl}?defaultsSaved=true`);
        }
        catch (error) {
            req.body = {
                title: 'Failed to save defaults',
                error: new ErrorHandler(error).formatError(),
                ...(req.body && { ...req.body }),
            };
            next(error);
        }
    };
    removeDefaultFilterValues = async (req, res, next) => {
        try {
            PersonalisationUtils.removeDefaults(FiltersType.INTERACTIVE, res, req, this.services);
            res.redirect(req.baseUrl);
        }
        catch (error) {
            req.body = {
                title: 'Failed to remove defaults',
                error: new ErrorHandler(error).formatError(),
                ...(req.body && { ...req.body }),
            };
            next(error);
        }
    };
    applyFilters = async (req, res, _next) => {
        await ViewReportUtils.applyReportInteractiveQuery(req, res, this.services, 'filters');
    };
    applyColumns = async (req, res, _next) => {
        await ViewReportUtils.applyReportInteractiveQuery(req, res, this.services, 'columns');
    };
}

export { ViewSyncReportController, ViewSyncReportController as default };
//# sourceMappingURL=controller.js.map
