USE whp;

-- NOTE: COLLATE=utf8mb4_unicode_ci is REQUIRED to match whp.sites.username
-- and whp.site_domains.fqdn — without it, JOINs against those columns throw
-- "Illegal mix of collations" since the DB-level default on some hosts is
-- utf8mb4_general_ci while existing tables explicitly use unicode_ci.

-- History of account-level disable/enable events
CREATE TABLE IF NOT EXISTS account_disable_audit (
  id          INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  username    VARCHAR(64) NOT NULL,
  action      ENUM('disable','enable') NOT NULL,
  reason      ENUM('unpaid','tos_violation','maintenance','admin_other') NULL,
  actor       VARCHAR(64) NOT NULL,
  note        TEXT NULL,
  created_at  DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_username_created (username, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Current state. Row exists iff the account is currently suspended.
CREATE TABLE IF NOT EXISTS accounts_disabled (
  username     VARCHAR(64) NOT NULL PRIMARY KEY,
  reason       ENUM('unpaid','tos_violation','maintenance','admin_other') NOT NULL,
  disabled_at  DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  disabled_by  VARCHAR(64) NOT NULL,
  note         TEXT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
