from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict

_env_path = Path(__file__).resolve().parent.parent.parent / ".env"
if not _env_path.exists():
    _env_path = Path(".env")


class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_file=str(_env_path), extra="ignore")

    DATABASE_URL: str = "postgresql+asyncpg://postgres:postgres123@db:5432/geo_platform"
    REDIS_URL: str = "redis://redis:6379/0"
    JWT_SECRET: str = "your-secret-key-change-in-production"
    JWT_EXPIRE_HOURS: int = 24
    PLAYWRIGHT_BROWSERS_PATH: str = "/ms-playwright"
    DEEPSEEK_API_KEY: str = ""
    ENABLE_LLM: bool = False
    ZHIPU_API_KEY: str = ""
    TONGYI_API_KEY: str = ""
    CORS_ORIGINS: str = "http://localhost:3000,http://localhost:3001"

    # ---- LLM Provider 配置 ----
    DEFAULT_LLM_PROVIDER: str = "openai"
    DEFAULT_LLM_MODEL: str = "qwen3-coder-plus"
    OPENAI_API_KEY: str = ""
    OPENAI_MODEL: str = "qwen3-coder-plus"
    OPENAI_BASE_URL: str = "https://coding.dashscope.aliyuncs.com/v1"
    DEEPSEEK_API_KEY: str = ""
    DEEPSEEK_MODEL: str = "deepseek-chat"
    DEEPSEEK_BASE_URL: str = "https://api.deepseek.com/v1"
    DEEPSEEK_MAX_CONTEXT: int = 64000

    # AI平台API配置
    MOONSHOT_API_KEY: str = ""          # Kimi (月之暗面) API Key
    BAIDU_QIANFAN_API_KEY: str = ""     # 百度千帆 API Key
    BAIDU_QIANFAN_SECRET_KEY: str = ""  # 百度千帆 Secret Key
    DOUBAO_API_KEY: str = ""            # 豆包 (字节跳动) API Key
    DOUBAO_ENDPOINT_ID: str = ""        # 豆包推理接入点 ID

    # AI平台API调用频率限制（每分钟请求数）
    API_RATE_LIMIT_RPM: int = 10


settings = Settings()
