"use strict";
/**
 * FilterPipeline — Records every filter decision for auditability.
 *
 * Tracks which findings were dismissed, downgraded, aggregated, or deduplicated
 * at each stage of the scanning pipeline. This enables answering
 * "why was finding X suppressed?" without rerunning the scan.
 *
 * Zero overhead by default — only records when explicitly enabled.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.FilterPipeline = void 0;
class FilterPipeline {
    constructor(enabled = false) {
        this.decisions = new Map();
        this.enabled = enabled;
    }
    /** Record a filter decision for a finding. No-op if pipeline is disabled. */
    record(findingId, decision) {
        if (!this.enabled)
            return;
        const existing = this.decisions.get(findingId);
        if (existing) {
            existing.push(decision);
        }
        else {
            this.decisions.set(findingId, [decision]);
        }
    }
    /** Get the full audit trail for all findings. */
    getAuditTrail() {
        const trail = [];
        for (const [findingId, decisions] of this.decisions) {
            const finalStatus = decisions.some(d => d.action === 'dismissed' || d.action === 'deduplicated' || d.action === 'suppressed') ? 'dismissed' : 'surfaced';
            trail.push({ findingId, decisions, finalStatus });
        }
        return trail;
    }
    /** Get all decisions that led to a specific finding being filtered. */
    explainDismissal(findingId) {
        return this.decisions.get(findingId) ?? [];
    }
    /** Get summary statistics per filter stage. */
    getSummaryStats() {
        const stages = [
            'file_context_adjustment',
            'localhost_aggregation',
            'noisy_aggregation',
            'auto_dismiss',
            'tier_filter',
            'ai_validation',
            'global_context',
            'contradiction_resolution',
            'deduplication',
            'user_suppression',
        ];
        const stats = {};
        for (const stage of stages) {
            stats[stage] = { dismissed: 0, downgraded: 0, kept: 0, aggregated: 0, deduplicated: 0, suppressed: 0 };
        }
        for (const decisions of this.decisions.values()) {
            for (const d of decisions) {
                if (stats[d.stage]) {
                    stats[d.stage][d.action]++;
                }
            }
        }
        return stats;
    }
    /** Whether this pipeline is actively recording. */
    get isEnabled() {
        return this.enabled;
    }
}
exports.FilterPipeline = FilterPipeline;
//# sourceMappingURL=pipeline.js.map