-- ============================================
-- 为 testuser 添加训练会话记录
-- ============================================

USE `kaopeilian`;

-- 获取 testuser 的 ID (应该是 1)
SET @test_user_id = 1;

-- 1. 先插入训练场景
INSERT INTO training_scenes (name, description, category, ai_config, status, is_public, is_deleted, created_by) VALUES
('Python编程助手', '帮助学员解决Python编程问题', '技术辅导', '{"bot_id": "python_assistant_bot"}', 'ACTIVE', 1, 0, 1),
('面试模拟', '模拟技术面试场景', '职业发展', '{"bot_id": "interview_simulator_bot"}', 'ACTIVE', 1, 0, 1),
('项目讨论', '项目方案讨论和优化', '项目管理', '{"bot_id": "project_discussion_bot"}', 'ACTIVE', 1, 0, 1);

-- 获取场景ID
SET @scene1_id = LAST_INSERT_ID();
SET @scene2_id = @scene1_id + 1;
SET @scene3_id = @scene1_id + 2;

-- 2. 添加训练会话记录（分布在最近15天）
INSERT INTO training_sessions (
    user_id, 
    scene_id, 
    start_time, 
    end_time, 
    duration_seconds, 
    status, 
    total_score,
    evaluation_result,
    created_by
) VALUES
-- 第一周
(@test_user_id, @scene1_id, '2025-09-08 09:00:00', '2025-09-08 09:45:00', 2700, 'COMPLETED', 85, '{"feedback": "表现良好"}', @test_user_id),
(@test_user_id, @scene2_id, '2025-09-09 14:00:00', '2025-09-09 15:00:00', 3600, 'COMPLETED', 88, '{"feedback": "面试表现不错"}', @test_user_id),
(@test_user_id, @scene1_id, '2025-09-10 10:00:00', '2025-09-10 10:30:00', 1800, 'COMPLETED', 82, '{"feedback": "继续努力"}', @test_user_id),
(@test_user_id, @scene3_id, '2025-09-11 13:30:00', '2025-09-11 15:00:00', 5400, 'COMPLETED', 90, '{"feedback": "项目思路清晰"}', @test_user_id),
(@test_user_id, @scene1_id, '2025-09-12 09:30:00', '2025-09-12 10:10:00', 2400, 'COMPLETED', 87, '{"feedback": "代码质量提升"}', @test_user_id),

-- 第二周
(@test_user_id, @scene2_id, '2025-09-13 14:30:00', '2025-09-13 15:20:00', 3000, 'COMPLETED', 85, '{"feedback": "算法掌握良好"}', @test_user_id),
(@test_user_id, @scene1_id, '2025-09-14 10:00:00', '2025-09-14 10:35:00', 2100, 'COMPLETED', 89, '{"feedback": "优秀"}', @test_user_id),
(@test_user_id, @scene3_id, '2025-09-15 13:00:00', '2025-09-15 14:15:00', 4500, 'COMPLETED', 91, '{"feedback": "架构设计合理"}', @test_user_id),
(@test_user_id, @scene1_id, '2025-09-16 09:15:00', '2025-09-16 10:00:00', 2700, 'COMPLETED', 86, '{"feedback": "进步明显"}', @test_user_id),
(@test_user_id, @scene2_id, '2025-09-17 14:00:00', '2025-09-17 14:55:00', 3300, 'COMPLETED', 88, '{"feedback": "表达清晰"}', @test_user_id),

-- 最近几天
(@test_user_id, @scene1_id, '2025-09-18 10:30:00', '2025-09-18 11:00:00', 1800, 'COMPLETED', 90, '{"feedback": "基础扎实"}', @test_user_id),
(@test_user_id, @scene3_id, '2025-09-19 13:00:00', '2025-09-19 14:20:00', 4800, 'COMPLETED', 92, '{"feedback": "解决方案优秀"}', @test_user_id),
(@test_user_id, @scene1_id, '2025-09-20 09:00:00', '2025-09-20 09:40:00', 2400, 'COMPLETED', 87, '{"feedback": "继续保持"}', @test_user_id),
(@test_user_id, @scene2_id, '2025-09-21 14:00:00', '2025-09-21 15:00:00', 3600, 'COMPLETED', 89, '{"feedback": "面试准备充分"}', @test_user_id),
(@test_user_id, @scene1_id, '2025-09-22 10:00:00', '2025-09-22 10:45:00', 2700, 'COMPLETED', 91, '{"feedback": "代码优雅"}', @test_user_id);

-- 查询验证
SELECT 
    COUNT(DISTINCT DATE(start_time)) as learning_days,
    ROUND(SUM(duration_seconds) / 3600, 1) as total_hours,
    COUNT(*) as session_count,
    ROUND(AVG(total_score), 1) as avg_score
FROM training_sessions 
WHERE user_id = @test_user_id;

SELECT '训练数据添加完成！' as message;
