-- Códigos de promoción (/promo-code): se canjean por PD y/o PV, con usos limitados.
-- BD: django_wow (DB.default). Ver lib/promo.ts.
-- `code` con collation *_bin => sensible a mayúsculas/minúsculas.
CREATE TABLE IF NOT EXISTS home_promocode (
  id         BIGINT       NOT NULL AUTO_INCREMENT,
  code       VARCHAR(64)  CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  pd         INT          NOT NULL DEFAULT 0,   -- PD (donate points) que otorga
  pv         INT          NOT NULL DEFAULT 0,   -- PV (vote points) que otorga
  max_uses   INT          NOT NULL DEFAULT 1,   -- usos totales permitidos
  uses       INT          NOT NULL DEFAULT 0,
  active     TINYINT      NOT NULL DEFAULT 1,
  expires_at DATETIME     NULL,                 -- NULL = sin caducidad
  created_at DATETIME     NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY uq_code (code)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Un canje por cuenta y código.
CREATE TABLE IF NOT EXISTS home_promoredemption (
  id          BIGINT   NOT NULL AUTO_INCREMENT,
  promo_id    BIGINT   NOT NULL,
  account_id  INT UNSIGNED NOT NULL,
  redeemed_at DATETIME NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY uq_promo_account (promo_id, account_id),
  KEY idx_account (account_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
