import * as fs from 'node:fs';
// ─── Public API ────────────────────────────────────
/**
 * Downgrade a rule from error to warning in compiled-rules.json.
 *
 * Returns whether the downgrade was applied.
 * Idempotent — skips rules already at warning severity.
 * Never deletes rules (ADR-027).
 */
export function downgradeRuleToWarning(rulesPath, ruleId) {
    const content = fs.readFileSync(rulesPath, 'utf-8');
    const data = JSON.parse(content);
    const rule = data.rules?.find((r) => r.lessonHash === ruleId);
    if (!rule)
        return { downgraded: false };
    const currentSeverity = rule.severity ?? 'error';
    if (currentSeverity !== 'error') {
        return {
            downgraded: false,
            previousSeverity: currentSeverity,
            ruleHeading: rule.lessonHeading,
        };
    }
    rule.severity = 'warning';
    // Preserve 2-space indent formatting
    fs.writeFileSync(rulesPath, JSON.stringify(data, null, 2) + '\n', 'utf-8');
    return {
        downgraded: true,
        previousSeverity: 'error',
        ruleHeading: rule.lessonHeading,
    };
}
//# sourceMappingURL=rule-mutator.js.map