# CONFIGURATION SETTINGS - Architecture Designer v2

import os
from typing import Optional
from loguru import logger

class Settings:
    """Configuration settings for Architecture Designer"""
    
    def __init__(self):
        # API Configuration
        self.api_host: str = os.getenv("API_HOST", "0.0.0.0")
        self.api_port: int = int(os.getenv("API_PORT", "8003"))
        self.debug: bool = os.getenv("DEBUG", "false").lower() == "true"
        
        # Claude AI Configuration
        self.claude_api_key: Optional[str] = os.getenv("ANTHROPIC_API_KEY")
        self.claude_model: str = os.getenv("CLAUDE_MODEL", "claude-3-sonnet-20240229")
        self.claude_max_tokens: int = int(os.getenv("CLAUDE_MAX_TOKENS", "4000"))
        
        # Service Configuration
        self.service_name: str = "architecture-designer-v2"
        self.service_version: str = "2.0.0"
        
        # Logging Configuration
        self.log_level: str = os.getenv("LOG_LEVEL", "INFO")
        
        # Validate settings
        self._validate_settings()
        
        logger.info("⚙️ Settings initialized successfully")
        if not self.claude_api_key:
            logger.warning("🔑 ANTHROPIC_API_KEY not set - Claude AI features will be limited")
    
    def _validate_settings(self):
        """Validate configuration settings"""
        if self.api_port < 1 or self.api_port > 65535:
            raise ValueError("API_PORT must be between 1 and 65535")
        
        if self.claude_max_tokens < 100 or self.claude_max_tokens > 8000:
            logger.warning("CLAUDE_MAX_TOKENS should be between 100 and 8000")
    
    @property
    def is_claude_available(self) -> bool:
        """Check if Claude AI is available"""
        return bool(self.claude_api_key)
    
    def get_claude_config(self) -> dict:
        """Get Claude AI configuration"""
        return {
            "api_key": self.claude_api_key,
            "model": self.claude_model,
            "max_tokens": self.claude_max_tokens
        }
