-- 题库表
CREATE TABLE IF NOT EXISTS question (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    content TEXT NOT NULL COMMENT '题目内容',
    category VARCHAR(100) NOT NULL COMMENT '题目分类',
    difficulty VARCHAR(20) NOT NULL COMMENT '难度等级',
    tags VARCHAR(500) COMMENT '标签，逗号分隔',
    created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    deleted TINYINT DEFAULT 0 COMMENT '逻辑删除标记'
);

-- 面试会话表
CREATE TABLE IF NOT EXISTS interview_session (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    session_id VARCHAR(64) UNIQUE NOT NULL COMMENT '会话唯一标识',
    candidate_name VARCHAR(100) COMMENT '候选人姓名',
    resume_content TEXT COMMENT '简历内容',
    extracted_skills TEXT COMMENT '提取的技能，JSON格式',
    ai_model VARCHAR(50) NOT NULL COMMENT '使用的AI模型',
    status VARCHAR(20) DEFAULT 'ACTIVE' COMMENT '会话状态：ACTIVE, COMPLETED, TERMINATED',
    total_questions INT DEFAULT 0 COMMENT '总问题数',
    current_question_index INT DEFAULT 0 COMMENT '当前问题索引',
    score DECIMAL(5,2) COMMENT '面试评分',
    selected_question_ids TEXT COMMENT 'AI选择的题目ID列表，JSON格式',
    final_report TEXT COMMENT 'AI生成的最终面试报告，JSON格式',
    created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    deleted TINYINT DEFAULT 0
);

-- 面试消息记录表
CREATE TABLE IF NOT EXISTS interview_message (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    session_id VARCHAR(64) NOT NULL COMMENT '会话ID',
    message_type VARCHAR(20) NOT NULL COMMENT '消息类型：QUESTION, ANSWER, SYSTEM',
    sender VARCHAR(20) NOT NULL COMMENT '发送者：AI, USER, SYSTEM',
    content TEXT NOT NULL COMMENT '消息内容',
    question_id BIGINT COMMENT '关联的题目ID',
    message_order INT NOT NULL COMMENT '消息顺序',
    created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_session_id (session_id),
    INDEX idx_session_order (session_id, message_order)
);

-- 面试评估表
CREATE TABLE IF NOT EXISTS interview_evaluation (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    session_id VARCHAR(64) NOT NULL COMMENT '会话ID',
    question_id BIGINT COMMENT '题目ID',
    user_answer TEXT COMMENT '用户回答',
    ai_feedback TEXT COMMENT 'AI反馈',
    score DECIMAL(3,1) COMMENT '单题得分',
    evaluation_criteria TEXT COMMENT '评估标准，JSON格式',
    created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_session_id (session_id)
);
