"""
课程考试设置模型
"""
from sqlalchemy import Column, Integer, ForeignKey, Boolean
from sqlalchemy.orm import relationship
from app.models.base import BaseModel, SoftDeleteMixin, AuditMixin


class CourseExamSettings(BaseModel, SoftDeleteMixin, AuditMixin):
    """课程考试设置表"""
    __tablename__ = "course_exam_settings"
    
    course_id = Column(Integer, ForeignKey("courses.id"), unique=True, nullable=False, comment="课程ID")
    
    # 题型数量设置
    single_choice_count = Column(Integer, default=4, nullable=False, comment="单选题数量")
    multiple_choice_count = Column(Integer, default=2, nullable=False, comment="多选题数量") 
    true_false_count = Column(Integer, default=1, nullable=False, comment="判断题数量")
    fill_blank_count = Column(Integer, default=2, nullable=False, comment="填空题数量")
    essay_count = Column(Integer, default=1, nullable=False, comment="问答题数量")
    
    # 考试参数设置
    duration_minutes = Column(Integer, default=10, nullable=False, comment="考试时长(分钟)")
    difficulty_level = Column(Integer, default=3, nullable=False, comment="难度系数(1-5)")
    passing_score = Column(Integer, default=60, nullable=False, comment="及格分数")
    
    # 其他设置
    is_enabled = Column(Boolean, default=True, nullable=False, comment="是否启用")
    show_answer_immediately = Column(Boolean, default=False, nullable=False, comment="是否立即显示答案")
    allow_retake = Column(Boolean, default=True, nullable=False, comment="是否允许重考")
    max_retake_times = Column(Integer, default=3, nullable=True, comment="最大重考次数")
    
    # 关系
    course = relationship("Course", backref="exam_settings", uselist=False)
