/**
 * Webhook source evaluator.
 *
 * Webhooks are push-based (an inbound signed HTTP delivery), so the poll-model
 * `evaluate` returns null. When a delivery arrives, the receiver matches it
 * against monitors with `matchWebhook`, which reuses the github/linear matchers
 * from lib/triggers/webhook.ts by projecting the monitor's webhook filters onto a
 * synthesized JobConfig-shaped trigger.
 */
import { jobMatchesWebhook } from '../../triggers/webhook.js';
/** Push-only: nothing to snapshot on a poll tick. */
export function evaluate(_source) {
    return Promise.resolve(null);
}
/** Project a monitor's webhook source onto a JobTrigger for the shared matcher. */
export function monitorTrigger(source) {
    const w = source.webhook;
    if (!w)
        return null;
    if (w.source === 'github') {
        return {
            type: 'github_event',
            event: w.event,
            ...(w.repo ? { repo: w.repo } : {}),
            ...(w.branch ? { branch: w.branch } : {}),
        };
    }
    return {
        type: 'linear_event',
        event: w.event,
        ...(w.action ? { action: w.action } : {}),
        ...(w.teamKey ? { teamKey: w.teamKey } : {}),
        ...(w.label ? { label: w.label } : {}),
    };
}
/**
 * True when an incoming webhook matches this monitor's webhook source — reuses
 * the routines matcher (lib/triggers/webhook.ts) so github/linear filter
 * semantics stay in one place.
 */
export function matchWebhook(monitor, webhook) {
    const trigger = monitorTrigger(monitor.source);
    if (!trigger)
        return false;
    const shim = { name: monitor.name, trigger };
    return jobMatchesWebhook(shim, webhook);
}
