-- ============================================================
-- V24: 新增第二个测试教练账号（李教练）
-- 描述: 
--   1. 新增测试教练用户 coachli（李教练）
--   2. 为李教练分配教练角色（继承教练的有限权限）
--   3. 为李教练分配未来一周的测试团课
-- 日期: 2026-06-22
-- ============================================================

-- ============================================================
-- 1. 第二个测试教练账号（密码: Test@123）
-- ============================================================
INSERT INTO sys_user (id, username, password, email, phone, nickname, status, create_by, update_by, created_at, updated_at)
VALUES (21, 'coachli', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'coachli@novalon.com', '13900000002', '李教练', 1, 'system', 'system', NOW(), NOW())
ON CONFLICT (username) DO NOTHING;

-- ============================================================
-- 2. 为李教练分配教练角色（role_id=5）
--    继承教练角色的所有有限权限
-- ============================================================
INSERT INTO user_role (user_id, role_id, created_by, created_at)
VALUES (21, 5, 'system', NOW())
ON CONFLICT (user_id, role_id) DO NOTHING;

-- ============================================================
-- 3. 为李教练分配测试团课（未来一周的课程）
-- ============================================================
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, create_by, created_at, updated_at)
VALUES
('入门瑜伽', 21, (SELECT id FROM group_course_type WHERE type_name = '瑜伽入门' LIMIT 1),
 CURRENT_DATE + INTERVAL '2 days' + TIME '09:00', CURRENT_DATE + INTERVAL '2 days' + TIME '10:00',
 15, 0, '0', '瑜伽教室', '适合零基础学员的入门瑜伽课程', 1, 'system', NOW(), NOW()),

('燃脂搏击', 21, (SELECT id FROM group_course_type WHERE type_name = '动感单车' LIMIT 1),
 CURRENT_DATE + INTERVAL '2 days' + TIME '15:00', CURRENT_DATE + INTERVAL '2 days' + TIME '16:00',
 20, 0, '0', '综合训练区', '高强度搏击操，燃烧卡路里', 2, 'system', NOW(), NOW()),

('肩颈理疗', 21, (SELECT id FROM group_course_type WHERE type_name = '普拉提' LIMIT 1),
 CURRENT_DATE + INTERVAL '4 days' + TIME '10:00', CURRENT_DATE + INTERVAL '4 days' + TIME '11:00',
 12, 0, '0', '普拉提教室', '针对久坐人群的肩颈放松课程', 1, 'system', NOW(), NOW()),

('晨间有氧', 21, (SELECT id FROM group_course_type WHERE type_name = 'HIIT训练' LIMIT 1),
 CURRENT_DATE + INTERVAL '5 days' + TIME '07:00', CURRENT_DATE + INTERVAL '5 days' + TIME '08:00',
 20, 0, '0', '有氧区', '清晨燃脂有氧训练，开启活力一天', 2, 'system', NOW(), NOW());

-- ============================================================
-- 4. 重置序列值
-- ============================================================
SELECT setval('sys_user_id_seq', GREATEST((SELECT COALESCE(MAX(id), 0) FROM sys_user), 21));
SELECT setval('group_course_id_seq', (SELECT COALESCE(MAX(id), 0) FROM group_course));
