CREATE TABLE IF NOT EXISTS `security_event_logs` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `uuid` CHAR(36) NOT NULL,
  `event_type` VARCHAR(120) NOT NULL,
  `severity` VARCHAR(30) NOT NULL DEFAULT 'warning',
  `user_id` BIGINT UNSIGNED NULL,
  `user_email` VARCHAR(255) NULL,
  `ip_address` VARCHAR(100) NULL,
  `user_agent` TEXT NULL,
  `method` VARCHAR(20) NULL,
  `url` TEXT NULL,
  `route_name` VARCHAR(150) NULL,
  `session_id_hash` VARCHAR(128) NULL,
  `request_id` VARCHAR(100) NULL,
  `subject_type` VARCHAR(100) NULL,
  `subject_id` VARCHAR(150) NULL,
  `metadata` LONGTEXT NULL,
  `detected_value_hash` VARCHAR(128) NULL,
  `detected_value_preview` VARCHAR(300) NULL,
  `status` VARCHAR(50) NOT NULL DEFAULT 'recorded',
  `created_at` TIMESTAMP NULL,
  `updated_at` TIMESTAMP NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `security_event_logs_uuid_unique` (`uuid`),
  KEY `security_event_logs_event_type_created_at_index` (`event_type`, `created_at`),
  KEY `security_event_logs_user_id_created_at_index` (`user_id`, `created_at`),
  KEY `security_event_logs_ip_address_created_at_index` (`ip_address`, `created_at`),
  KEY `security_event_logs_request_id_index` (`request_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
