import os
from typing import Dict, Any

class Config:
    """系统配置类"""
    
    # 阿里云千问API配置
    ALIBABA_API_KEY = "sk-c0dbefa1718d46eaa897199135066f00"
    ALIBABA_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
    ALIBABA_MODEL_NAME = "qwen-plus-latest"
    
    # 数据库配置
    DATABASE_URL = "mysql+pymysql://tsp_assistant:123456@jeason.online/tsp_assistant?charset=utf8mb4"
    
    # 知识库配置
    KNOWLEDGE_BASE_PATH = "data/knowledge_base"
    VECTOR_DB_PATH = "data/vector_db"
    
    # 对话配置
    MAX_HISTORY_LENGTH = 10
    RESPONSE_TIMEOUT = 30
    
    # 分析配置
    ANALYTICS_UPDATE_INTERVAL = 3600  # 1小时
    ALERT_THRESHOLD = 0.8  # 预警阈值
    
    # 日志配置
    LOG_LEVEL = "INFO"
    LOG_FILE = "logs/tsp_assistant.log"
    
    # 系统监控配置
    SYSTEM_MONITORING = True  # 是否启用系统监控
    MONITORING_INTERVAL = 60  # 监控间隔（秒）
    
    @classmethod
    def get_api_config(cls) -> Dict[str, Any]:
        """获取API配置"""
        return {
            "api_key": cls.ALIBABA_API_KEY,
            "base_url": cls.ALIBABA_BASE_URL,
            "model_name": cls.ALIBABA_MODEL_NAME
        }
    
    @classmethod
    def get_database_config(cls) -> Dict[str, Any]:
        """获取数据库配置"""
        return {
            "url": cls.DATABASE_URL,
            "echo": False
        }
    
    @classmethod
    def get_knowledge_config(cls) -> Dict[str, Any]:
        """获取知识库配置"""
        return {
            "base_path": cls.KNOWLEDGE_BASE_PATH,
            "vector_db_path": cls.VECTOR_DB_PATH
        }
    
    @classmethod
    def get_config(cls) -> Dict[str, Any]:
        """获取完整配置"""
        return {
            "system_monitoring": cls.SYSTEM_MONITORING,
            "monitoring_interval": cls.MONITORING_INTERVAL,
            "log_level": cls.LOG_LEVEL,
            "log_file": cls.LOG_FILE,
            "analytics_update_interval": cls.ANALYTICS_UPDATE_INTERVAL,
            "alert_threshold": cls.ALERT_THRESHOLD
        }
