"""Legacy-compatible config used by older utility modules."""

from pathlib import Path

from pydantic_settings import BaseSettings, SettingsConfigDict

# Keep legacy settings aligned with the root-level env loading rules.


ROOT_DIR = Path(__file__).resolve().parents[3]
ROOT_ENV_FILES = tuple(str(path) for path in (ROOT_DIR / ".env", ROOT_DIR / ".env.development"))


class Settings(BaseSettings):
    # DashScope API
    """Define configuration for settings."""

    model_config = SettingsConfigDict(
        env_file=ROOT_ENV_FILES,
        env_file_encoding="utf-8",
        case_sensitive=False,
        extra="ignore",
    )

    dashscope_api_key: str = ""

    # Milvus
    milvus_host: str = "6.86.80.8"
    milvus_port: int = 19530
    milvus_collection: str = "regulations_dense_1024_v2"

    # LLM / embedding defaults aligned with the migrated backend path.
    llm_model: str = "qwen-max"
    embedding_model: str = "text-embedding-v3"
    embedding_dim: int = 1024

    # Legacy workflow compatibility only.
    vector_top_k: int = 10
    final_top_k: int = 5

    # Legacy local chunking compatibility only; main ingest now uses Aliyun vector_chunks.
    chunk_size: int = 800
    chunk_overlap: int = 50

    # Service config.
    api_host: str = "0.0.0.0"
    api_port: int = 8000

    # Legacy aliases retained for old utility modules.
    regulations_collection: str = "regulations_dense_1024_v2"
    compliance_collection: str = "compliance_cache"

# Preserve the legacy module API while keeping env resolution centralized at the repo root.
settings = Settings()
