"""
知识库自定义Schema定义模型
"""
from sqlalchemy import Column, String, Integer, Boolean, Text, DateTime, func
from sqlalchemy.dialects.mysql import CHAR, TINYINT
from app.base.async_mysql_connection import Base
import uuid

class CustomSchema(Base):
    """知识库自定义Schema表"""
    __tablename__ = "t_samp_custom_schema"

    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_name = Column(String(255), nullable=False, comment="字段名称(英文)")
    field_type = Column(String(50), nullable=False, comment="字段类型")
    max_length = Column(Integer, nullable=True, comment="最大长度")
    is_primary = Column(Boolean, default=False, comment="是否主键")
    description = Column(String(1000), nullable=True, comment="描述")
    
    created_time = Column(DateTime, default=func.now(), comment="创建时间")
    updated_time = Column(DateTime, default=func.now(), onupdate=func.now(), comment="修改时间")

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