"""
知识库数据库模型
"""
from sqlalchemy import Column, String, Integer, Text, Boolean
from sqlalchemy.dialects.mysql import CHAR, TINYINT
from app.base.async_mysql_connection import Base
from app.models.base import BaseModel


class KnowledgeBase(BaseModel):
    """知识库模型"""
    __tablename__ = "t_samp_knowledge_base"

    name = Column(String(100), nullable=False, comment="知识库名称")
    collection_name_parent = Column(String(100), nullable=True, unique=True, comment="Milvus集合名称(Table Name)(父)")
    collection_name_children = Column(String(100), nullable=True, comment="Milvus集合名称(Table Name)(子)")
    has_parent_collection = Column(TINYINT, default=1, comment="是否有父集合: 1-有, 0-无")
    description = Column(String(500), nullable=True, comment="描述")
    # 默认禁用，只有同步成功后才置为 normal
    status = Column(String(20), default="disabled", comment="状态: normal(正常), test(测试), disabled(禁用)")
    document_count = Column(Integer, default=0, comment="文档数量")
    is_deleted = Column(TINYINT, default=0, comment="是否删除")
    created_by = Column(String(500), nullable=True, comment="创建人")
    updated_by = Column(String(500), nullable=True, comment="修改人")
    created_time = Column(String(500), nullable=True, comment="创建时间")
    updated_time = Column(String(500), nullable=True, comment="修改时间")

    def __repr__(self):
        return f"<KnowledgeBase {self.name}>"
