"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServiceCompletionPolicy = void 0;
class ServiceCompletionPolicy {
    requiredCriteria = [
        'Provisionamento concluído',
        'Integração entre módulos validada',
        'Fluxo ponta-a-ponta testado',
        'Observabilidade mínima registrada',
        'Operação real documentada'
    ];
    requiredEvidenceTypes = ['provisioning', 'integration', 'e2e', 'observability', 'operation'];
    enforceCriteria(criteria) {
        const merged = [...criteria];
        for (const required of this.requiredCriteria) {
            if (!merged.some((item) => item.toLowerCase() === required.toLowerCase())) {
                merged.push(required);
            }
        }
        return merged;
    }
    evaluate(state) {
        const missing = [];
        const attempts = state.attempts || [];
        const successAttempts = attempts.filter((a) => a.status === 'success' || a.status === 'partial').length;
        if (!state.plan || state.plan.length < 3)
            missing.push('plano com etapas suficientes');
        if (!state.successCriteria || state.successCriteria.length < this.requiredCriteria.length)
            missing.push('critérios de serviço completo');
        if (successAttempts < 2)
            missing.push('evidência de execução e validação');
        if (!state.artifacts || state.artifacts.length === 0)
            missing.push('artefatos operacionais');
        const passedEvidence = (state.serviceEvidence || []).filter((item) => item.status === 'passed');
        for (const type of this.requiredEvidenceTypes) {
            const evidence = passedEvidence.find((item) => item.type === type);
            if (!evidence) {
                missing.push(`serviceEvidence.${type}`);
                continue;
            }
            if (!evidence.summary || evidence.summary.trim().length === 0) {
                missing.push(`serviceEvidence.${type}.summary`);
            }
            if ((type === 'operation') && (!evidence.command || evidence.command.trim().length === 0)) {
                missing.push('serviceEvidence.operation.command');
            }
        }
        return { complete: missing.length === 0, missing };
    }
}
exports.ServiceCompletionPolicy = ServiceCompletionPolicy;
