-- 0004_webhooks.sql

CREATE TABLE IF NOT EXISTS merchant_webhooks (
    webhook_id VARCHAR PRIMARY KEY,
    merchant_id VARCHAR NOT NULL REFERENCES merchants(merchant_id) ON DELETE CASCADE,
    url TEXT NOT NULL,
    secret VARCHAR NOT NULL,
    events JSONB NOT NULL DEFAULT '["order.created", "order.shipped", "order.delivered", "order.disputed", "risk.alert"]'::jsonb,
    is_active BOOLEAN NOT NULL DEFAULT TRUE,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_webhooks_merchant ON merchant_webhooks(merchant_id);
