"""
能力评估模型
用于存储智能工牌数据分析、练习报告等产生的能力评估结果
"""
from sqlalchemy import Column, Integer, String, DateTime, JSON, ForeignKey, Text
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.models.base import Base


class AbilityAssessment(Base):
    """能力评估历史表"""
    __tablename__ = "ability_assessments"
    
    id = Column(Integer, primary_key=True, index=True, comment='主键ID')
    user_id = Column(
        Integer, 
        ForeignKey('users.id', ondelete='CASCADE'), 
        nullable=False,
        comment='用户ID'
    )
    source_type = Column(
        String(50), 
        nullable=False, 
        comment='数据来源: yanji_badge(智能工牌), practice_report(练习报告), manual(手动评估)'
    )
    source_id = Column(
        String(100), 
        comment='来源记录ID（如录音ID列表，逗号分隔）'
    )
    total_score = Column(
        Integer, 
        comment='综合评分(0-100)'
    )
    ability_dimensions = Column(
        JSON, 
        nullable=False, 
        comment='6个能力维度评分JSON数组'
    )
    recommended_courses = Column(
        JSON, 
        comment='推荐课程列表JSON数组'
    )
    conversation_count = Column(
        Integer, 
        comment='分析的对话数量'
    )
    analyzed_at = Column(
        DateTime, 
        server_default=func.now(), 
        comment='分析时间'
    )
    created_at = Column(
        DateTime, 
        server_default=func.now(),
        comment='创建时间'
    )
    
    # 关系
    # user = relationship("User", back_populates="ability_assessments")
    
    def __repr__(self):
        return f"<AbilityAssessment(id={self.id}, user_id={self.user_id}, total_score={self.total_score})>"

