from __future__ import annotations

from sqlalchemy import BigInteger, Boolean, Integer, String, Text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column

from fastapi_common.fastapi_common_web.models import BaseModel


class LeauditRagDataset(BaseModel):
    __tablename__ = "rag_dataset"

    Id: Mapped[int] = mapped_column("id", BigInteger, primary_key=True, autoincrement=True)
    name: Mapped[str] = mapped_column(String(255), comment="知识库名称")
    description: Mapped[str] = mapped_column(Text, default="", comment="知识库描述")
    area: Mapped[str] = mapped_column(String(50), default="", comment="地区")
    isPublic: Mapped[bool] = mapped_column("is_public", Boolean, default=False)
    isDefault: Mapped[bool] = mapped_column("is_default", Boolean, default=False)
    collectionName: Mapped[str] = mapped_column("collection_name", String(100), unique=True)
    embeddingModel: Mapped[str] = mapped_column("embedding_model", String(100), default="text-embedding-v4")
    embeddingDim: Mapped[int] = mapped_column("embedding_dim", Integer, default=1024)
    chunkMaxSize: Mapped[int] = mapped_column("chunk_max_size", Integer, default=800)
    chunkMinSize: Mapped[int] = mapped_column("chunk_min_size", Integer, default=20)
    documentCount: Mapped[int] = mapped_column("document_count", Integer, default=0)
    totalChunks: Mapped[int] = mapped_column("total_chunks", Integer, default=0)
    retrievalModel: Mapped[dict] = mapped_column("retrieval_model", JSONB, default=dict)
    sortOrder: Mapped[int] = mapped_column("sort_order", Integer, default=0)
    status: Mapped[int] = mapped_column(Integer, default=1)
    createdBy: Mapped[int | None] = mapped_column("created_by", BigInteger)
    updatedBy: Mapped[int | None] = mapped_column("updated_by", BigInteger)
