import { evaluateQualityGate, } from '../../../../modules/tracking/entities/qualityGate/qualityGate.js';
function buildRevertMessage(reason, threshold, latestScore) {
    if (reason === 'below-threshold') {
        return `Approbation annulée : seuil qualité ${threshold}/10 non atteint (${latestScore}/10). Utilisez \`/bypass-quality "raison"\` pour forcer.`;
    }
    return 'Approbation annulée : issues bloquantes non résolues. Utilisez `/bypass-quality "raison"` pour forcer.';
}
export class HandlePlatformApprovalUseCase {
    trackingGateway;
    constructor(trackingGateway) {
        this.trackingGateway = trackingGateway;
    }
    execute(input) {
        const mr = this.trackingGateway.getById(input.projectPath, input.mrId);
        if (!mr)
            return { kind: 'mr-not-found' };
        if (mr.bypass !== null)
            return { kind: 'bypass-active' };
        const gateResult = evaluateQualityGate({
            latestScore: mr.latestScore,
            blockingIssues: mr.openThreads,
            threshold: input.qualityThreshold,
        });
        if (gateResult.allowed)
            return { kind: 'allowed' };
        const latestScore = mr.latestScore ?? 0;
        const threshold = input.qualityThreshold ?? 0;
        return {
            kind: 'reverted',
            reason: gateResult.reason,
            threshold,
            latestScore,
            message: buildRevertMessage(gateResult.reason, threshold, latestScore),
        };
    }
}
//# sourceMappingURL=handlePlatformApproval.usecase.js.map