-- 跟单计划表
CREATE TABLE IF NOT EXISTS `follow_plans` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `game_id` int(11) NOT NULL DEFAULT 1,
  `name` varchar(100) NOT NULL COMMENT '计划名称，如：大小计划、单双计划',
  `plan_type` varchar(30) NOT NULL COMMENT '计划类型：bs(大小), oe(单双), dt(龙虎), sum_bs(冠亚大小)',
  `target_rank` int(11) NOT NULL DEFAULT 1 COMMENT '目标名次 1-10',
  `strategy` varchar(30) NOT NULL DEFAULT 'follow' COMMENT '策略：follow(跟投), reverse(反投)',
  `bet_amount` decimal(15,2) NOT NULL DEFAULT 100.00 COMMENT '每期建议投注额',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1=启用 0=禁用',
  `created_by` int(11) DEFAULT NULL COMMENT '创建管理员ID',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_game_status` (`game_id`, `status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 跟单计划每期推荐记录
CREATE TABLE IF NOT EXISTS `follow_plan_records` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `plan_id` int(11) NOT NULL,
  `period_id` int(11) NOT NULL,
  `period_number` varchar(50) NOT NULL,
  `recommend_value` varchar(20) NOT NULL COMMENT '推荐值：big/small/odd/even/dragon/tiger',
  `result_value` varchar(20) DEFAULT NULL COMMENT '实际结果',
  `is_win` tinyint(1) DEFAULT NULL COMMENT '1=赢 0=输 NULL=未开奖',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_plan_period` (`plan_id`, `period_id`),
  KEY `idx_plan_id` (`plan_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 用户跟单记录
CREATE TABLE IF NOT EXISTS `user_follow_plans` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `plan_id` int(11) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否正在跟单',
  `total_bets` int(11) NOT NULL DEFAULT 0 COMMENT '总跟注期数',
  `total_wins` int(11) NOT NULL DEFAULT 0 COMMENT '总赢期数',
  `total_profit` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT '累计盈亏',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_user_plan` (`user_id`, `plan_id`),
  KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
