from pydantic_settings import BaseSettings
from functools import lru_cache
from pathlib import Path


class Settings(BaseSettings):
    """应用配置"""
   
    # Jingrow API配置
    jingrow_server_url: str = ''
    jingrow_api_key: str = ''
    jingrow_api_secret: str = ''
    jingrow_session_cookie: str = ''
    jingrow_site: str = ''
    
    # Jingrow Cloud API配置
    jingrow_cloud_url: str = 'https://cloud.jingrow.com'
    jingrow_cloud_api_url: str = 'https://api.jingrow.com'
    jingrow_cloud_api_key: str = ''
    jingrow_cloud_api_secret: str = ''
    
    # 数据库配置
    jingrow_db_host: str = 'localhost'
    jingrow_db_port: str = '3306'
    jingrow_db_name: str = 'jingrow_local'
    jingrow_db_user: str = 'root'
    jingrow_db_password: str = ''
    jingrow_db_type: str = 'mariadb'
    
    # Qdrant 向量数据库配置
    qdrant_host: str = ''
    qdrant_port: int = 6333
    
    # 运行模式
    run_mode: str = 'api'
    
    class Config:
        env_file = str(Path(__file__).parent.parent / '.env')
        env_file_encoding = 'utf-8'
        case_sensitive = False


@lru_cache()
def get_settings() -> Settings:
    """获取配置实例（单例模式）"""
    return Settings()


# 全局配置实例
Config = get_settings()