"""
岗位课程关联模型
"""
from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean, Enum, UniqueConstraint
from sqlalchemy.orm import relationship
from app.models.base import BaseModel, SoftDeleteMixin


class PositionCourse(BaseModel, SoftDeleteMixin):
    """岗位课程关联表"""
    __tablename__ = "position_courses"
    
    # 添加唯一约束：同一岗位下同一课程只能有一条有效记录
    __table_args__ = (
        UniqueConstraint('position_id', 'course_id', 'is_deleted', name='uix_position_course'),
    )
    
    position_id = Column(Integer, ForeignKey("positions.id"), nullable=False, comment="岗位ID")
    course_id = Column(Integer, ForeignKey("courses.id"), nullable=False, comment="课程ID")
    
    # 课程类型：required（必修）、optional（选修）
    course_type = Column(String(20), default="required", nullable=False, comment="课程类型")
    priority = Column(Integer, default=0, comment="优先级/排序")
    
    # 关系
    position = relationship("Position", back_populates="courses")
    course = relationship("Course", back_populates="position_assignments")
