-- apps/web/src/server/db/migrations/0071_referral_settings.sql
-- Apply via Neon MCP run_sql against project rough-brook-49654702.

CREATE TABLE IF NOT EXISTS referral_settings (
  id                                INTEGER PRIMARY KEY CHECK (id = 1),
  affiliate_pct                     INTEGER NOT NULL DEFAULT 30,
  affiliate_window_days             INTEGER NOT NULL DEFAULT 90,
  affiliate_max_orders              INTEGER NOT NULL DEFAULT 50,
  cookie_days                       INTEGER NOT NULL DEFAULT 14,
  reward_agorot                     INTEGER NOT NULL DEFAULT 2000,
  referee_discount_agorot           INTEGER NOT NULL DEFAULT 2000,
  hold_days                         INTEGER NOT NULL DEFAULT 30,
  withdrawal_min_agorot             INTEGER NOT NULL DEFAULT 30000,
  auto_approve_lifetime_agorot      INTEGER NOT NULL DEFAULT 50000,
  brand_keyword_blocklist           TEXT[] NOT NULL DEFAULT ARRAY['multideal','מולטידיל','multi.deal'],
  disallowed_referer_hosts          TEXT[] NOT NULL DEFAULT '{}',
  tos_version                       TEXT NOT NULL DEFAULT 'v1-2026-05-28',
  updated_at                        TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_by_user_id                UUID REFERENCES users(id)
);

INSERT INTO referral_settings (id) VALUES (1) ON CONFLICT DO NOTHING;
