"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCustomMetricAnalysis = void 0;
const logger_1 = require("../../../logger");
const getCustomMetricAnalysis = async (req, res) => {
    try {
        const { output, context } = req.body;
        const vars = context?.vars;
        if (typeof output !== 'string') {
            res.status(400).json({
                pass: false,
                score: 0,
                reason: 'Invalid output type — expected a string.',
            });
            return;
        }
        const outputLower = output.toLowerCase();
        const varValues = Object.values(vars).map((v) => String(v).toLowerCase());
        // Check if all variable values are contained in the output
        const missingValues = varValues.filter((v) => !outputLower.includes(v));
        const pass = missingValues.length === 0;
        const score = pass ? 1 : (varValues.length - missingValues.length) / varValues.length;
        const reason = pass
            ? `Output contains all required values: ${varValues.join(', ')}.`
            : `Missing values: ${missingValues.join(', ')}.`;
        res.json({
            pass,
            score,
            reason,
        });
    }
    catch (error) {
        logger_1.logger.error(`Error in getCustomMetricAnalysis: ${error}`);
        res.status(500).json({
            pass: false,
            score: 0,
            reason: 'Internal server error',
        });
    }
};
exports.getCustomMetricAnalysis = getCustomMetricAnalysis;
//# sourceMappingURL=customMetric.js.map