from functools import lru_cache
from pathlib import Path

from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    # LLM access
    llm_base_url: str = "https://openrouter.ai/api/v1"
    llm_api_key: str = ""
    llm_model_name: str = "qwen/qwen3.5-35b-a3b"
    llm_enable_thinking: bool = False

    # Embeddings
    embedding_model: str = "qwen/qwen3-embedding-4b"
    embedding_base_url: str = "https://openrouter.ai/api/v1"
    embedding_api_key: str = ""

    # ChromaDB
    chroma_db_path: str = "./chroma_db"

    # App configuration moved to settings for easier testing/configuration
    # Cross-origin settings and chunking parameters (Phase 1 plan)
    cors_origins: list[str] = ["http://localhost:5173", "http://localhost:3000"]
    chunk_size: int = 1000
    chunk_overlap: int = 200
    retrieval_n_results: int = 10
    relevance_threshold: float = 7.0
    llm_timeout: float = 60.0

    # Development helpers
    model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}


@lru_cache
def get_settings() -> Settings:
    return Settings()
