/**
 * sinks/types.ts
 *
 * The ReportSink interface — the contract for all report delivery destinations.
 *
 * Sinks receive published reports and deliver them to external systems
 * (BigQuery, Slack, GitHub, webhooks, etc.). Each sink is self-contained:
 * it handles its own connection, schema mapping, and error handling.
 *
 * Design principle P6: Sinks are fire-and-forget. A sink failure is logged
 * but never blocks the pipeline, the Sanity write, or other sinks.
 *
 * @see docs/design-docs/report-store/sink-architecture.md
 */
/**
 * Check whether a sink should receive a delivery based on its routing
 * rules and the payload's severity/comparison data.
 *
 * Returns true (deliver) when:
 * - The sink has no routing config (backward compatible — receives everything)
 * - The payload's maxSeverity matches an enabled routing rule
 * - The payload has regressions and the sink's `regression` rule is enabled
 *
 * @see docs/archive/exec-plans/scenario-matrix-implementation/phase-5-readiness-thresholds.md
 */
export function shouldDeliver(routing, payload) {
    // No routing config = deliver everything (backward compatible)
    if (!routing)
        return true;
    // Check severity-based routing
    if (payload.maxSeverity !== "none") {
        const severityRule = routing[payload.maxSeverity];
        if (severityRule)
            return true;
    }
    // Check regression routing
    if (routing.regression &&
        payload.comparison &&
        payload.comparison.regressed.length > 0) {
        return true;
    }
    // No matching rule — skip
    return false;
}
