-- ============================================
-- 火箭系统数据库初始化脚本
-- ============================================

-- 1. 创建火箭配置表
CREATE TABLE IF NOT EXISTS `rocket_config` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `level` TINYINT UNSIGNED NOT NULL COMMENT '火箭等级 1/2/3',
  `max_energy` BIGINT UNSIGNED NOT NULL COMMENT '最大能量值',
  `reward_config` JSON DEFAULT NULL COMMENT '奖励配置(JSON,预留)',
  `contributor_reward_rate` DECIMAL(5,2) DEFAULT NULL COMMENT '贡献者奖励比例%',
  `normal_reward_config` JSON DEFAULT NULL COMMENT '普通用户奖励配置(JSON,预留)',
  `status` TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态 1:启用 0:禁用',
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_level` (`level`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='火箭配置表';

-- 2. 插入初始配置数据
INSERT INTO `rocket_config` (`level`, `max_energy`, `status`) VALUES
(1, 150000, 1),
(2, 500000, 1),
(3, 1000000, 1)
ON DUPLICATE KEY UPDATE `max_energy` = VALUES(`max_energy`);

-- 3. 创建奖励领取记录表
CREATE TABLE IF NOT EXISTS `rocket_reward_claim_log` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `rocket_history_id` VARCHAR(32) NOT NULL COMMENT '火箭历史记录ID(MongoDB _id)',
  `room_id` BIGINT UNSIGNED NOT NULL COMMENT '房间ID',
  `user_id` BIGINT UNSIGNED NOT NULL COMMENT '用户ID',
  `rocket_level` TINYINT UNSIGNED NOT NULL COMMENT '火箭等级',
  `is_contributor` TINYINT UNSIGNED NOT NULL COMMENT '是否贡献者 1:是 0:否',
  `contribution_energy` BIGINT UNSIGNED DEFAULT 0 COMMENT '贡献能量值',
  `contribution_rate` DECIMAL(8,4) DEFAULT 0.0000 COMMENT '贡献率%',
  `reward_type` VARCHAR(32) NOT NULL COMMENT '奖励类型 GOLD/DIAMOND/PROP',
  `reward_item_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '奖励物品ID',
  `reward_amount` BIGINT UNSIGNED NOT NULL COMMENT '奖励数量',
  `wallet_biz_no` VARCHAR(64) DEFAULT NULL COMMENT '钱包业务单号',
  `claimed_at` DATETIME NOT NULL COMMENT '领取时间',
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_rocket_user` (`rocket_history_id`, `user_id`),
  KEY `idx_room_id` (`room_id`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_claimed_at` (`claimed_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='火箭奖励领取记录表';
