"""
知识库元数据定义模型
"""
from sqlalchemy import Column, String, Text, DateTime, func
from sqlalchemy.dialects.mysql import CHAR, TINYINT
from app.base.async_mysql_connection import Base
import uuid

class SampleMetadata(Base):
    """知识库元数据定义表"""
    __tablename__ = "t_samp_metadata"

    id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()), comment="主键ID")
    knowledge_base_id = Column(String(36), nullable=False, comment="知识库ID")
    field_zh_name = Column(String(255), nullable=False, comment="字段名称(中文)")
    field_en_name = Column(String(500), nullable=False, comment="字段英文名称")
    field_type = Column(String(10), nullable=False, comment="字段类型: text(文本), num(数字)")
    remark = Column(String(1000), nullable=True, comment="备注")
    
    def to_dict(self) -> dict:
        """转换为字典"""
        return {
            column.name: getattr(self, column.name)
            for column in self.__table__.columns
        }

    def __repr__(self):
        return f"<SampleMetadata kb_id={self.knowledge_base_id} field={self.field_en_name}>"
