CREATE TABLE IF NOT EXISTS `smash_egg_config` (
  `id` bigint NOT NULL COMMENT '主键ID',
  `sys_origin` varchar(32) NOT NULL COMMENT '来源系统',
  `enabled` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否启用',
  `timezone` varchar(64) NOT NULL DEFAULT 'Asia/Riyadh' COMMENT '业务时区',
  `rtp_basis_points` int NOT NULL DEFAULT '9500' COMMENT '目标RTP，万分比',
  `create_time` datetime(3) DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime(3) DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_smash_egg_config_sys_origin` (`sys_origin`),
  KEY `idx_smash_egg_config_enabled` (`enabled`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='常驻活动砸蛋配置';

CREATE TABLE IF NOT EXISTS `smash_egg_draw_option_config` (
  `id` bigint NOT NULL COMMENT '主键ID',
  `config_id` bigint NOT NULL COMMENT '主配置ID',
  `sys_origin` varchar(32) NOT NULL COMMENT '来源系统',
  `option_key` varchar(32) NOT NULL DEFAULT '' COMMENT '按钮标识',
  `label` varchar(64) NOT NULL DEFAULT '' COMMENT '按钮文案',
  `times` int NOT NULL DEFAULT '1' COMMENT '抽奖次数',
  `price_gold` bigint NOT NULL DEFAULT '0' COMMENT '该按钮消耗金币',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `enabled` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否启用',
  `create_time` datetime(3) DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime(3) DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_smash_egg_option_config` (`config_id`, `sort`),
  KEY `idx_smash_egg_option_enabled` (`sys_origin`, `enabled`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='常驻活动砸蛋按钮配置';

CREATE TABLE IF NOT EXISTS `smash_egg_reward_config` (
  `id` bigint NOT NULL COMMENT '主键ID',
  `config_id` bigint NOT NULL COMMENT '主配置ID',
  `sys_origin` varchar(32) NOT NULL COMMENT '来源系统',
  `reward_type` varchar(32) NOT NULL COMMENT '奖励类型 RESOURCE_GROUP/GOLD',
  `reward_group_id` bigint DEFAULT NULL COMMENT '资源组ID',
  `reward_group_name` varchar(255) NOT NULL DEFAULT '' COMMENT '资源组名称快照',
  `cover_url` varchar(512) NOT NULL DEFAULT '' COMMENT '封面图',
  `animation_url` varchar(512) NOT NULL DEFAULT '' COMMENT '动态图',
  `duration_days` int NOT NULL DEFAULT '0' COMMENT '资源组展示天数',
  `gold_amount` bigint NOT NULL DEFAULT '0' COMMENT '金币数量',
  `reward_value_gold` bigint NOT NULL DEFAULT '0' COMMENT '奖品折算金币价值，用于RTP计算',
  `probability` int NOT NULL DEFAULT '0' COMMENT '中奖概率，100%=1000000',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `enabled` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否启用',
  `create_time` datetime(3) DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime(3) DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_smash_egg_reward_config` (`config_id`, `sort`),
  KEY `idx_smash_egg_reward_enabled` (`sys_origin`, `enabled`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='常驻活动砸蛋奖励配置';

CREATE TABLE IF NOT EXISTS `smash_egg_draw_record` (
  `id` bigint NOT NULL COMMENT '主键ID',
  `draw_no` varchar(64) NOT NULL COMMENT '抽奖单号',
  `event_id` varchar(128) NOT NULL COMMENT '奖励发放幂等事件ID',
  `sys_origin` varchar(32) NOT NULL COMMENT '来源系统',
  `user_id` bigint NOT NULL COMMENT '用户ID',
  `draw_option_id` bigint NOT NULL DEFAULT '0' COMMENT '按钮配置ID',
  `draw_times` int NOT NULL DEFAULT '1' COMMENT '本次抽奖次数',
  `paid_gold` bigint NOT NULL DEFAULT '0' COMMENT '本次消耗金币',
  `reward_type` varchar(32) NOT NULL COMMENT '奖励类型 RESOURCE_GROUP/GOLD',
  `reward_group_id` bigint DEFAULT NULL COMMENT '资源组ID',
  `reward_group_name` varchar(255) NOT NULL DEFAULT '' COMMENT '资源组名称快照',
  `cover_url` varchar(512) NOT NULL DEFAULT '' COMMENT '封面图快照',
  `animation_url` varchar(512) NOT NULL DEFAULT '' COMMENT '动态图快照',
  `duration_days` int NOT NULL DEFAULT '0' COMMENT '天数快照',
  `gold_amount` bigint NOT NULL DEFAULT '0' COMMENT '金币数量快照',
  `reward_value_gold` bigint NOT NULL DEFAULT '0' COMMENT '奖品折算金币价值',
  `probability` int NOT NULL DEFAULT '0' COMMENT '概率快照，100%=1000000',
  `status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT '状态 PENDING/SUCCESS/FAILED',
  `error_message` varchar(1024) NOT NULL DEFAULT '' COMMENT '失败原因',
  `create_time` datetime(3) DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime(3) DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_smash_egg_draw_record_event` (`event_id`),
  KEY `idx_smash_egg_draw_record_draw_no` (`draw_no`),
  KEY `idx_smash_egg_draw_record_user_time` (`sys_origin`, `user_id`, `create_time`),
  KEY `idx_smash_egg_draw_record_day` (`sys_origin`, `create_time`),
  KEY `idx_smash_egg_draw_record_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='常驻活动砸蛋抽奖记录';
