-- Phase 4 migration: webhook ingress.
-- The secret_token column holds the SECRETS-STORE KEY under which the actual
-- shared token lives (NOT the token plaintext) — see DECISIONS.md D25.

CREATE TABLE IF NOT EXISTS webhook_endpoints (
    id                   TEXT PRIMARY KEY,
    name                 TEXT NOT NULL,
    secret_token         TEXT NOT NULL,     -- key into secrets table, not the token itself
    enabled              INTEGER NOT NULL DEFAULT 1,
    handler_type         TEXT NOT NULL,     -- "autobrr" | "qbit" | "crossseed" | "generic"
    handler_config_json  TEXT,
    created_at           INTEGER NOT NULL,
    last_called_at       INTEGER
);
CREATE INDEX IF NOT EXISTS idx_webhook_endpoints_handler
    ON webhook_endpoints(handler_type);
