CREATE TABLE IF NOT EXISTS `rate_limit_blocks` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `block_type` ENUM('ip', 'user') NOT NULL,
  `cache_identifier` VARCHAR(191) NOT NULL COMMENT 'fingerprint for ip, hashed identity for user',
  `display_identifier` VARCHAR(255) NOT NULL COMMENT 'actual IP or email/mobile for admin display',
  `block_level` ENUM('soft', 'medium', 'hard') NOT NULL,
  `status` ENUM('active', 'unblocked') NOT NULL DEFAULT 'active',
  `blocked_at` DATETIME NOT NULL,
  `unblocked_at` DATETIME NULL DEFAULT NULL,
  `unblocked_by` BIGINT NULL DEFAULT NULL,
  `unblock_reason` VARCHAR(255) NULL DEFAULT NULL,
  `meta_json` LONGTEXT NULL,
  `created_at` DATETIME NOT NULL,
  `updated_at` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_rate_limit_block` (`block_type`, `cache_identifier`),
  KEY `idx_rate_limit_status` (`status`, `block_type`),
  KEY `idx_rate_limit_level` (`block_level`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
