-- 添加 2 个小节课测试数据
-- 执行方式：psql -U your_username -d your_database -f add_two_single_courses.sql

-- ============================================================
-- 小节课 1：5分钟时间管理
-- ============================================================

-- 插入小节课 1
INSERT INTO courses (id, title, type, total_nodes, created_at)
VALUES ('course_single_001', '5分钟时间管理', 'single', 1, NOW())
ON CONFLICT (id) DO UPDATE SET 
    title = EXCLUDED.title,
    type = 'single',
    total_nodes = EXCLUDED.total_nodes;

-- 插入对应的节点
INSERT INTO course_nodes (id, course_id, title, order_index, created_at)
VALUES ('node_single_001', 'course_single_001', '时间管理的核心原则', 0, NOW())
ON CONFLICT (id) DO UPDATE SET 
    course_id = EXCLUDED.course_id,
    title = EXCLUDED.title,
    order_index = EXCLUDED.order_index;

-- 为节点创建基础幻灯片（4张幻灯片）
INSERT INTO node_slides (id, node_id, slide_type, order_index, content, effect, created_at)
VALUES 
    (
        'slide_single_001_01',
        'node_single_001',
        'text',
        1,
        '{"title": "5分钟时间管理", "paragraphs": ["欢迎学习时间管理核心原则", "让我们快速掌握高效的时间管理方法"]}'::jsonb,
        'fade_in',
        NOW()
    ),
    (
        'slide_single_001_02',
        'node_single_001',
        'text',
        2,
        '{"title": "核心原则", "paragraphs": ["1. 优先级排序：重要且紧急的事情优先", "2. 番茄工作法：25分钟专注，5分钟休息", "3. 时间块：为每个任务分配固定时间"]}'::jsonb,
        'fade_in',
        NOW()
    ),
    (
        'slide_single_001_03',
        'node_single_001',
        'text',
        3,
        '{"title": "实践要点", "paragraphs": ["每天早上列出今日最重要的3件事", "使用番茄钟保持专注", "每天晚上回顾完成情况"]}'::jsonb,
        'fade_in',
        NOW()
    ),
    (
        'slide_single_001_04',
        'node_single_001',
        'text',
        4,
        '{"title": "本节小结", "paragraphs": ["你已经完成了「时间管理的核心原则」的学习", "记住：高效的时间管理需要持续练习", "每天进步一点点，最终会带来巨大的改变"]}'::jsonb,
        'fade_in',
        NOW()
    )
ON CONFLICT (id) DO UPDATE SET
    slide_type = EXCLUDED.slide_type,
    order_index = EXCLUDED.order_index,
    content = EXCLUDED.content,
    effect = EXCLUDED.effect;

-- ============================================================
-- 小节课 2：3分钟学会专注
-- ============================================================

-- 插入小节课 2
INSERT INTO courses (id, title, type, total_nodes, created_at)
VALUES ('course_single_002', '3分钟学会专注', 'single', 1, NOW())
ON CONFLICT (id) DO UPDATE SET 
    title = EXCLUDED.title,
    type = 'single',
    total_nodes = EXCLUDED.total_nodes;

-- 插入对应的节点
INSERT INTO course_nodes (id, course_id, title, order_index, created_at)
VALUES ('node_single_002', 'course_single_002', '专注力的训练方法', 0, NOW())
ON CONFLICT (id) DO UPDATE SET 
    course_id = EXCLUDED.course_id,
    title = EXCLUDED.title,
    order_index = EXCLUDED.order_index;

-- 为节点创建基础幻灯片（4张幻灯片）
INSERT INTO node_slides (id, node_id, slide_type, order_index, content, effect, created_at)
VALUES 
    (
        'slide_single_002_01',
        'node_single_002',
        'text',
        1,
        '{"title": "3分钟学会专注", "paragraphs": ["欢迎学习专注力的训练方法", "让我们快速掌握提升专注力的技巧"]}'::jsonb,
        'fade_in',
        NOW()
    ),
    (
        'slide_single_002_02',
        'node_single_002',
        'text',
        2,
        '{"title": "专注的原理", "paragraphs": ["专注力是一种可以训练的能力", "大脑需要时间进入专注状态（约15分钟）", "减少干扰是提升专注的关键"]}'::jsonb,
        'fade_in',
        NOW()
    ),
    (
        'slide_single_002_03',
        'node_single_002',
        'text',
        3,
        '{"title": "实用技巧", "paragraphs": ["关闭所有通知和干扰源", "设置专门的专注时间和空间", "使用深呼吸帮助快速进入专注状态"]}'::jsonb,
        'fade_in',
        NOW()
    ),
    (
        'slide_single_002_04',
        'node_single_002',
        'text',
        4,
        '{"title": "本节小结", "paragraphs": ["你已经完成了「专注力的训练方法」的学习", "记住：专注力需要持续练习", "从每天15分钟开始，逐步提升专注时长"]}'::jsonb,
        'fade_in',
        NOW()
    )
ON CONFLICT (id) DO UPDATE SET
    slide_type = EXCLUDED.slide_type,
    order_index = EXCLUDED.order_index,
    content = EXCLUDED.content,
    effect = EXCLUDED.effect;

-- ============================================================
-- 验证数据
-- ============================================================

SELECT 
    c.id as course_id,
    c.title as course_title,
    c.type,
    c.total_nodes,
    n.id as node_id,
    n.title as node_title,
    n.order_index,
    (SELECT COUNT(*) FROM node_slides WHERE node_id = n.id) as slide_count
FROM courses c
LEFT JOIN course_nodes n ON c.id = n.course_id
WHERE c.id IN ('course_single_001', 'course_single_002')
ORDER BY c.id, n.order_index;

