CREATE TABLE saldo_kaget (
  id VARCHAR(20) PRIMARY KEY,
  kode VARCHAR(12) NOT NULL UNIQUE,
  qr_code TEXT NOT NULL,
  nominal INT NOT NULL,
  jumlah_penerima INT NOT NULL,
  sisa_penerima INT NOT NULL,
  sisa_saldo INT NOT NULL,
  nama_pembuat VARCHAR(150) NOT NULL,
  email_pembuat VARCHAR(190) NOT NULL,
  id_pembuat VARCHAR(64) NOT NULL,
  tipe ENUM('rata','acak') NOT NULL,
  status ENUM('aktif','selesai','batal') NOT NULL DEFAULT 'aktif',
  detail_pembagian_json LONGTEXT NULL,
  created_at BIGINT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE saldo_kaget_claims (
  id BIGINT AUTO_INCREMENT PRIMARY KEY,
  saldo_kaget_id VARCHAR(20) NOT NULL,
  kode VARCHAR(12) NOT NULL,
  nama_penerima VARCHAR(150) NOT NULL,
  email_penerima VARCHAR(190) NOT NULL,
  id_penerima VARCHAR(64) NOT NULL,
  jumlah INT NOT NULL,
  api_response_json JSON NULL,
  claimed_at BIGINT NOT NULL,
  UNIQUE KEY uniq_campaign_email (saldo_kaget_id, email_penerima),
  UNIQUE KEY uniq_campaign_user (saldo_kaget_id, id_penerima),
  INDEX idx_kode (kode)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;