"""项目配置文件"""

import os
from typing import Optional


class Config:
    """全局配置类"""
    
    # API 配置 - 使用属性动态获取环境变量
    @classmethod
    def get_api_key(cls) -> Optional[str]:
        """动态获取API密钥"""
        return os.getenv("DEEPSEEK_API_KEY")
    
    @classmethod
    def get_base_url(cls) -> str:
        """动态获取API基础URL"""
        return os.getenv("DEEPSEEK_BASE_URL", "https://api.deepseek.com/v1")
    
    DEEPSEEK_MODEL: str = "deepseek-chat"
    
    # 应用配置
    MAX_RETRY_ATTEMPTS: int = 3
    REQUEST_TIMEOUT: int = 30
    CACHE_EXPIRY: int = 300  # 5分钟缓存
    
    # 情感分析配置
    SENTIMENT_THRESHOLDS = {
        "high_confidence": 0.8,
        "medium_confidence": 0.6,
        "low_confidence": 0.4
    }
    
    # 航空公司配置
    AIRLINES = [
        "United", "US Airways", "American", "Southwest", "Delta", "Virgin America",
        "JetBlue", "Alaska", "Frontier", "Spirit", "Hawaiian"
    ]
    
    # UI 配置
    MAX_DISPLAY_FACTORS: int = 5
    MAX_DISPLAY_ACTIONS: int = 4
    
    @classmethod
    def validate_config(cls) -> bool:
        """验证配置是否有效"""
        api_key = cls.get_api_key()
        if not api_key:
            print("⚠️ 警告: DEEPSEEK_API_KEY 未配置")
            return False
        return True
    
    @classmethod
    def validate_config_with_message(cls) -> tuple[bool, str]:
        """验证配置并返回详细消息"""
        api_key = cls.get_api_key()
        base_url = cls.get_base_url()
        
        if not api_key:
            return False, "API 密钥未配置，请检查 .env 文件"
        
        # 检查API密钥格式
        if not api_key.startswith("sk-"):
            return False, "API 密钥格式不正确，应以 'sk-' 开头"
        
        # 检查URL格式
        if base_url and not base_url.startswith("http"):
            return False, "API 地址格式不正确，应以 'http' 或 'https' 开头"
        
        return True, "API 配置正常"
    
    @classmethod
    def get_available_airlines(cls) -> list[str]:
        """获取可用的航空公司列表"""
        return cls.AIRLINES