"""
Configuration file for Code Assistant Bot
Author: RSK World (https://rskworld.in)
Founder: Molla Samser
Designer & Tester: Rima Khatun
Contact: help@rskworld.in, +91 93305 39277
Year: 2026
"""

import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

class Config:
    """
    Configuration class for Code Assistant Bot
    """
    
    # Flask Configuration
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'dev-secret-key-change-in-production'
    DEBUG = os.environ.get('FLASK_ENV', 'development') == 'development'
    PORT = int(os.environ.get('PORT', 5000))
    
    # OpenAI Configuration
    OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
    OPENAI_MODEL = os.environ.get('OPENAI_MODEL', 'gpt-3.5-turbo')
    OPENAI_MAX_TOKENS = int(os.environ.get('OPENAI_MAX_TOKENS', 1500))
    OPENAI_TEMPERATURE = float(os.environ.get('OPENAI_TEMPERATURE', 0.7))
    
    # GitHub Configuration
    GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN')
    GITHUB_API_URL = 'https://api.github.com'
    
    # Application Configuration
    MAX_CODE_LENGTH = int(os.environ.get('MAX_CODE_LENGTH', 10000))
    RATE_LIMIT_PER_MINUTE = int(os.environ.get('RATE_LIMIT_PER_MINUTE', 60))
    
    # Logging Configuration
    LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
    LOG_FILE = os.environ.get('LOG_FILE', 'code_assistant_bot.log')
    
    # Supported Programming Languages
    SUPPORTED_LANGUAGES = [
        'python', 'javascript', 'typescript', 'java', 'cpp', 'c', 'csharp',
        'php', 'ruby', 'go', 'rust', 'html', 'css', 'sql', 'swift', 'kotlin'
    ]
    
    # Code Analysis Configuration
    COMPLEXITY_THRESHOLDS = {
        'low': 5,
        'medium': 10,
        'high': 20
    }
    
    # Security Configuration
    ENABLE_CORS = True
    CORS_ORIGINS = ['*']  # In production, specify allowed origins
    
    # Cache Configuration (for future implementation)
    CACHE_TYPE = 'simple'
    CACHE_DEFAULT_TIMEOUT = 300
    
    # Database Configuration (for future features)
    DATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite:///code_assistant_bot.db')
    
    @staticmethod
    def validate_config():
        """
        Validate required configuration values
        """
        errors = []
        
        if not Config.OPENAI_API_KEY:
            errors.append("OPENAI_API_KEY is required")
        
        if errors:
            raise ValueError("Configuration validation failed: " + ", ".join(errors))
        
        return True

class DevelopmentConfig(Config):
    """
    Development configuration
    """
    DEBUG = True
    LOG_LEVEL = 'DEBUG'

class ProductionConfig(Config):
    """
    Production configuration
    """
    DEBUG = False
    LOG_LEVEL = 'WARNING'
    CORS_ORIGINS = ['https://rskworld.in']  # Restrict to your domain in production

class TestingConfig(Config):
    """
    Testing configuration
    """
    TESTING = True
    OPENAI_API_KEY = 'test-key'  # Mock key for testing
    LOG_LEVEL = 'DEBUG'

# Configuration mapping
config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'testing': TestingConfig,
    'default': DevelopmentConfig
}
