"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionalChartsController = void 0;
const logger_1 = __importDefault(require("../../../logger"));
const functionalChartsService_1 = require("../../services/functionalChartsService");
const defaultStart = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString();
const defaultEnd = new Date().toISOString();
exports.FunctionalChartsController = {
    async getFunctionalTestStats(req, res) {
        try {
            const { applicationId, projectId, start, end } = req.query;
            const startStr = start || defaultStart;
            const endStr = end || defaultEnd;
            const data = await functionalChartsService_1.functionalChartsService.getFunctionalTestStats({
                timeLimit: { start: startStr, end: endStr },
                projectId: projectId ?? '',
                applicationId: applicationId ?? '',
            });
            res.json({ success: true, data });
        }
        catch (error) {
            logger_1.default.error(`Error in getFunctionalTestStats: ${error}`);
            res.status(500).json({
                success: false,
                message: error.message,
                error: error.message,
            });
        }
    },
    async getFunctionalEvaluationsTrend(req, res) {
        try {
            const { applicationId, projectId, start, end } = req.query;
            const startStr = start || defaultStart;
            const endStr = end || defaultEnd;
            const data = await functionalChartsService_1.functionalChartsService.getFunctionalEvaluationsTrend({
                timeLimit: { start: startStr, end: endStr },
                projectId: projectId ?? '',
                applicationId: applicationId ?? '',
            });
            res.json({ success: true, data });
        }
        catch (error) {
            logger_1.default.error(`Error in getFunctionalEvaluationsTrend: ${error}`);
            res.status(500).json({
                success: false,
                message: error.message,
                error: error.message,
            });
        }
    },
    async getRecentFunctionalEvaluations(req, res) {
        try {
            const { applicationId, projectId, start, end, limit } = req.query;
            const startStr = start || defaultStart;
            const endStr = end || defaultEnd;
            const list = await functionalChartsService_1.functionalChartsService.getRecentFunctionalEvaluations({
                timeLimit: { start: startStr, end: endStr },
                projectId: projectId ?? '',
                applicationId: applicationId ?? '',
                limit: limit != null ? Number(limit) : undefined,
            });
            res.json({ success: true, data: list });
        }
        catch (error) {
            logger_1.default.error(`Error in getRecentFunctionalEvaluations: ${error}`);
            res.status(500).json({
                success: false,
                message: error.message,
                error: error.message,
            });
        }
    },
    async getTestCaseResultsOverTime(req, res) {
        try {
            const { applicationId, projectId, start, end } = req.query;
            const startStr = start || defaultStart;
            const endStr = end || defaultEnd;
            const graphData = await functionalChartsService_1.functionalChartsService.getTestCaseResultsOverTime({
                timeLimit: { start: startStr, end: endStr },
                projectId: projectId ?? '',
                applicationId: applicationId ?? '',
            });
            res.json({ success: true, data: { graphData } });
        }
        catch (error) {
            logger_1.default.error(`Error in getTestCaseResultsOverTime: ${error}`);
            res.status(500).json({
                success: false,
                message: error.message,
                error: error.message,
            });
        }
    },
    async getTopMetricFailures(req, res) {
        try {
            const { applicationId, projectId, start, end } = req.query;
            const startStr = start || defaultStart;
            const endStr = end || defaultEnd;
            const data = await functionalChartsService_1.functionalChartsService.getTopMetricFailures({
                timeLimit: { start: startStr, end: endStr },
                projectId: projectId ?? '',
                applicationId: applicationId ?? '',
            });
            res.json({ success: true, data });
        }
        catch (error) {
            logger_1.default.error(`Error in getTopMetricFailures: ${error}`);
            res.status(500).json({
                success: false,
                message: error.message,
                error: error.message,
            });
        }
    },
};
//# sourceMappingURL=index.js.map