"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.assessFinalReportContractCompleteness = assessFinalReportContractCompleteness;
const sceneClassifier_1 = require("../agentv3/sceneClassifier");
const strategyLoader_1 = require("../agentv3/strategyLoader");
function patternMatches(text, pattern) {
    try {
        return new RegExp(pattern, 'i').test(text);
    }
    catch {
        return text.toLowerCase().includes(pattern.toLowerCase());
    }
}
function requirementSatisfied(text, requirement) {
    if (requirement.patternGroups.length > 0) {
        return requirement.patternGroups.every(group => group.some(pattern => patternMatches(text, pattern)));
    }
    return requirement.patterns.some(pattern => patternMatches(text, pattern));
}
function normalizeSceneType(value) {
    const normalized = String(value || '').trim().toLowerCase();
    if (!normalized)
        return undefined;
    if (normalized === 'jank' || normalized === 'scroll' || normalized === 'scrolling')
        return 'scrolling';
    if (normalized === 'cold_start' || normalized === 'warm_start' || normalized === 'hot_start')
        return 'startup';
    return normalized;
}
function assessFinalReportContractCompleteness(input) {
    const sceneType = normalizeSceneType(input.sceneType) ||
        normalizeSceneType(input.contractSceneId) ||
        (0, sceneClassifier_1.classifyScene)(input.query || '');
    const contract = (0, strategyLoader_1.getFinalReportContract)(sceneType);
    if (!contract || contract.requiredSections.length === 0)
        return undefined;
    const missingLabels = contract.requiredSections
        .filter(requirement => requirement.required !== false)
        .filter(requirement => !requirementSatisfied(input.conclusion, requirement))
        .map(requirement => requirement.label || requirement.id);
    if (missingLabels.length === 0)
        return undefined;
    return { sceneType, missingLabels };
}
//# sourceMappingURL=finalReportContractGate.js.map