"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObserveChartsController = void 0;
exports.isMongoId = isMongoId;
const observeCharts_1 = require("../../services/observe/observeCharts");
const logger_1 = __importDefault(require("../../../logger"));
function isMongoId(id) {
    if (typeof id !== "string")
        return false;
    return /^[a-fA-F0-9]{24}$/.test(id);
}
exports.ObserveChartsController = {
    getTokenConsumptionPerModelDonut: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTokenConsumptionPerModelDonut(payload);
            res.status(200).json({ success: true, message: 'Token consumption per model (donut) fetched successfully', data });
        }
        catch (error) {
            logger_1.default.error(`Error fetching token consumption per model (donut): ${error}`);
            res.status(500).json({ success: false, message: 'Failed to fetch token consumption per model (donut)' });
        }
    },
    getTokenConsumptionPerModelChart: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTokenConsumptionPerModelChart(payload);
            res.status(200).json({ success: true, message: 'Token consumption per model (chart) fetched successfully', data });
        }
        catch (error) {
            logger_1.default.error(`Error fetching token consumption per model (chart): ${error}`);
            res.status(500).json({ success: false, message: 'Failed to fetch token consumption per model (chart)' });
        }
    },
    getTokenConsumptionPerAgentDonut: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTokenConsumptionPerAgentDonut(payload);
            res.status(200).json({ success: true, message: 'Token consumption per agent (donut) fetched successfully', data });
        }
        catch (error) {
            logger_1.default.error(`Error fetching token consumption per agent (donut): ${error}`);
            res.status(500).json({ success: false, message: 'Failed to fetch token consumption per agent (donut)' });
        }
    },
    getTokenConsumptionPerAgentChart: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTokenConsumptionPerAgentChart(payload);
            res.status(200).json({ success: true, message: 'Token consumption per agent (chart) fetched successfully', data });
        }
        catch (error) {
            logger_1.default.error(`Error fetching token consumption per agent (chart): ${error}`);
            res.status(500).json({ success: false, message: 'Failed to fetch token consumption per agent (chart)' });
        }
    },
    getToolCallBreakdown: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getToolCallBreakdown(payload);
            res.status(200).json({
                success: true,
                message: 'Tool call breakdown fetched successfully',
                data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching tool call breakdown: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch tool call breakdown',
            });
        }
    },
    getResponseTimeByModel: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getResponseTimeByModel(payload);
            res.status(200).json({ success: true, message: 'Response time by model fetched successfully', data });
        }
        catch (error) {
            logger_1.default.error(`Error fetching response time by model: ${error}`);
            res.status(500).json({ success: false, message: 'Failed to fetch response time by model' });
        }
    },
    getResponseTimeByModelSummary: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getResponseTimeByModelSummary(payload);
            res.status(200).json({ success: true, message: 'Response time by model summary fetched successfully', data });
        }
        catch (error) {
            logger_1.default.error(`Error fetching response time by model summary: ${error}`);
            res.status(500).json({ success: false, message: 'Failed to fetch response time by model summary' });
        }
    },
    getResponseTimeByAgent: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getResponseTimeByAgent(payload);
            res.status(200).json({ success: true, message: 'Response time by agent fetched successfully', data });
        }
        catch (error) {
            logger_1.default.error(`Error fetching response time by agent: ${error}`);
            res.status(500).json({ success: false, message: 'Failed to fetch response time by agent' });
        }
    },
    getResponseTimeByAgentSummary: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getResponseTimeByAgentSummary(payload);
            res.status(200).json({ success: true, message: 'Response time by agent summary fetched successfully', data });
        }
        catch (error) {
            logger_1.default.error(`Error fetching response time by agent summary: ${error}`);
            res.status(500).json({ success: false, message: 'Failed to fetch response time by agent summary' });
        }
    },
    getAgentRunBreakdown: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getAgentRunBreakdown(payload);
            res.status(200).json({
                success: true,
                message: 'Agent run breakdown fetched successfully',
                data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching agent run breakdown: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch agent run breakdown',
            });
        }
    },
    getAgentRunAnalysis: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getAgentRunAnalysis(payload);
            res.status(200).json({
                success: true,
                message: 'Agent run analysis fetched successfully',
                data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching agent run analysis: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch agent run analysis',
            });
        }
    },
    getSlowestPromptsAnalysis: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getSlowestPromptsAnalysis(payload);
            res.status(200).json({
                success: true,
                message: 'Slowest prompts analysis fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching slowest prompts analysis: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch slowest prompts analysis',
            });
        }
    },
    getExpensivePromptsAnalysis: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getExpensivePromptsAnalysis(payload);
            res.status(200).json({
                success: true,
                message: 'Expensive prompts analysis fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching expensive prompts analysis: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch expensive prompts analysis',
            });
        }
    },
    getAgentAnalysisSummary: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getAgentAnalysisSummary(payload);
            res.status(200).json({
                success: true,
                message: 'Agent analysis summary fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching agent analysis summary: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch agent analysis summary',
            });
        }
    },
    getSystemHealth: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getSystemHealth(payload);
            res.status(200).json({
                success: true,
                message: 'System health fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching system health: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch system health',
            });
        }
    },
    getGroup1Metrics: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getGroup1Metrics(payload);
            res.status(200).json({
                success: true,
                message: 'Group1 metrics fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching group1 metrics: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch group1 metrics',
            });
        }
    },
    getGroup2Metrics: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getGroup2Metrics(payload);
            res.status(200).json({
                success: true,
                message: 'Group2 metrics fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching group2 metrics: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch group2 metrics',
            });
        }
    },
    getSingleMetric: async (req, res) => {
        const metricKey = req.params.metricKey;
        const payload = req.body;
        try {
            const value = await observeCharts_1.observeChartsService.getSingleMetric(metricKey, payload);
            res.status(200).json({
                success: true,
                message: 'Metric fetched successfully',
                data: value,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching single metric (${metricKey}): ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch metric',
            });
        }
    },
    getCacheReadTokens: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getCacheReadTokens(payload);
            res.status(200).json({
                success: true,
                message: 'Cache read tokens fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching cache read tokens: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch cache read tokens',
            });
        }
    },
    getCacheSummaryMetrics: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getCacheSummaryMetrics(payload);
            res.status(200).json({
                success: true,
                message: 'Cache summary metrics fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching cache summary metrics: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch cache summary metrics',
            });
        }
    },
    getTimeToFirstTokenHistogram: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTimeToFirstTokenHistogram(payload);
            res.status(200).json({
                success: true,
                message: 'Time to first token histogram fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching time to first token histogram: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch time to first token histogram',
            });
        }
    },
    getTotalResponseTimeHistogram: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTotalResponseTimeHistogram(payload);
            res.status(200).json({
                success: true,
                message: 'Total response time histogram fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching total response time histogram: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch total response time histogram',
            });
        }
    },
    getTimeToFirstTokenVsResponseTime: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTimeToFirstTokenVsResponseTime(payload);
            res.status(200).json({
                success: true,
                message: 'Time to first token vs response time fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching time to first token vs response time: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch time to first token vs response time',
            });
        }
    },
    getTimeToFirstTokenScatter: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTimeToFirstTokenScatter(payload);
            res.status(200).json({
                success: true,
                message: 'Time to first token scatter fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching time to first token scatter: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch time to first token scatter',
            });
        }
    },
    getTracesPerTime: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTracesPerTime(payload);
            res.status(200).json({
                success: true,
                message: 'Traces per time fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching traces per time: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch traces per time',
            });
        }
    },
    getTimeToFirstTokenChart: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTimeToFirstTokenChart(payload);
            res.status(200).json({
                success: true,
                message: 'Time to first token chart fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching time to first token chart: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch time to first token chart',
            });
        }
    },
    getResponseTimeChart: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getResponseTimeChart(payload);
            res.status(200).json({
                success: true,
                message: 'Response time chart fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching response time chart: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch response time chart',
            });
        }
    },
    getTokensAnalysis: async (req, res) => {
        const payload = req.body;
        try {
            const data = await observeCharts_1.observeChartsService.getTokensAnalysis(payload);
            res.status(200).json({
                success: true,
                message: 'Tokens analysis fetched successfully',
                data: data,
            });
        }
        catch (error) {
            logger_1.default.error(`Error fetching tokens analysis: ${error}`);
            res.status(500).json({
                success: false,
                message: 'Failed to fetch tokens analysis',
            });
        }
    },
};
//# sourceMappingURL=observe-charts-controller.js.map