ALTER TABLE `devx_characters`
  ADD COLUMN IF NOT EXISTS `phone_number` VARCHAR(16) NULL AFTER `model`;

CREATE UNIQUE INDEX IF NOT EXISTS `uq_devx_character_phone`
  ON `devx_characters` (`phone_number`);

CREATE TABLE IF NOT EXISTS `devx_bans` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `license` VARCHAR(80) NOT NULL,
  `player_name` VARCHAR(96) NULL,
  `reason` VARCHAR(255) NOT NULL,
  `banned_by` VARCHAR(96) NOT NULL,
  `expires_at` DATETIME NULL,
  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `revoked_at` DATETIME NULL,
  PRIMARY KEY (`id`),
  KEY `idx_devx_bans_license` (`license`),
  KEY `idx_devx_bans_active` (`license`, `revoked_at`, `expires_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `devx_heist_progress` (
  `character_id` BIGINT UNSIGNED NOT NULL,
  `drill_done` TINYINT(1) NOT NULL DEFAULT 0,
  `card_done` TINYINT(1) NOT NULL DEFAULT 0,
  `vehicle_done` TINYINT(1) NOT NULL DEFAULT 0,
  `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`character_id`),
  CONSTRAINT `fk_devx_heist_character`
    FOREIGN KEY (`character_id`) REFERENCES `devx_characters` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `devx_casino_daily` (
  `character_id` BIGINT UNSIGNED NOT NULL,
  `last_spin` DATETIME NULL,
  `total_spins` INT UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`character_id`),
  CONSTRAINT `fk_devx_casino_character`
    FOREIGN KEY (`character_id`) REFERENCES `devx_characters` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
