-- 创建训练会话表
CREATE TABLE t_workout_sessions (
    id VARCHAR(36) PRIMARY KEY DEFAULT (UUID()),
    user_id VARCHAR(255) NOT NULL COMMENT '用户ID',
    training_plan_id VARCHAR(36) NOT NULL COMMENT '关联的训练计划模板',
    name VARCHAR(255) NOT NULL COMMENT '训练会话名称',
    scheduled_date DATETIME NOT NULL COMMENT '计划训练日期',
    started_at DATETIME NULL COMMENT '实际开始时间',
    completed_at DATETIME NULL COMMENT '实际结束时间',
    status ENUM('planned', 'in_progress', 'completed', 'skipped') NOT NULL DEFAULT 'planned' COMMENT '训练状态',
    total_duration_sec INT NULL COMMENT '总时长(秒)',
    summary TEXT NULL COMMENT '训练总结/备注',
    calories_burned INT NULL COMMENT '消耗卡路里(估算)',
    stats JSON NULL COMMENT '训练统计数据',
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    deleted BOOLEAN DEFAULT FALSE COMMENT '是否已删除',
    
    -- 外键约束
    FOREIGN KEY (training_plan_id) REFERENCES t_training_plans(id),
    
    -- 索引
    INDEX idx_user_id (user_id),
    INDEX idx_training_plan_id (training_plan_id),
    INDEX idx_scheduled_date (scheduled_date),
    INDEX idx_status (status),
    INDEX idx_deleted (deleted)
);

-- 添加表注释
ALTER TABLE t_workout_sessions COMMENT = '训练会话表';