-- ─────────────────────────────────────────────────────────────────
-- FASE 5: Notificações e Área do Ganhador
-- ─────────────────────────────────────────────────────────────────

CREATE TABLE IF NOT EXISTS notifications (
  id            SERIAL PRIMARY KEY,
  user_cpf      TEXT NOT NULL,
  title         TEXT NOT NULL,
  message       TEXT NOT NULL,
  type          TEXT DEFAULT 'info', -- 'info', 'win', 'alert'
  read_at       TIMESTAMPTZ,
  created_at    TIMESTAMPTZ DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS raffle_claims (
  id                SERIAL PRIMARY KEY,
  raffle_id         INTEGER NOT NULL REFERENCES raffles(id) ON DELETE CASCADE,
  ticket_id         INTEGER NOT NULL REFERENCES tickets(id),
  user_cpf          TEXT NOT NULL,
  status            TEXT DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'delivered')),
  delivery_address  TEXT,
  delivery_notes    TEXT,
  claimed_at        TIMESTAMPTZ DEFAULT NOW(),
  updated_at        TIMESTAMPTZ DEFAULT NOW()
);
