"""
AI Settings - Centralized model configurations and limits
"""
from typing import Dict, Any

# Model configurations for each AI function
MODEL_CONFIG = {
    "auto_cluster": {
        "model": "gpt-4o-mini",
        "max_tokens": 3000,
        "temperature": 0.7,
        "response_format": {"type": "json_object"},  # Auto-enabled for JSON mode models
    },
    "generate_ideas": {
        "model": "gpt-4.1",
        "max_tokens": 4000,
        "temperature": 0.7,
        "response_format": {"type": "json_object"},  # JSON output
    },
    "generate_content": {
        "model": "gpt-4.1",
        "max_tokens": 8000,
        "temperature": 0.7,
        "response_format": {"type": "json_object"},  # JSON output
    },
    "generate_images": {
        "model": "dall-e-3",
        "size": "1024x1024",
        "provider": "openai",
    },
    "extract_image_prompts": {
        "model": "gpt-4o-mini",
        "max_tokens": 1000,
        "temperature": 0.7,
        "response_format": {"type": "json_object"},
    },
}

# Function name aliases (for backward compatibility)
FUNCTION_ALIASES = {
    "cluster_keywords": "auto_cluster",
    "auto_cluster_keywords": "auto_cluster",
    "auto_generate_ideas": "generate_ideas",
    "auto_generate_content": "generate_content",
    "auto_generate_images": "generate_images",
}


def get_model_config(function_name: str) -> Dict[str, Any]:
    """
    Get model configuration for an AI function.
    
    Args:
        function_name: AI function name (e.g., 'auto_cluster', 'generate_ideas')
    
    Returns:
        Dict with model, max_tokens, temperature, etc.
    """
    # Check aliases first
    actual_name = FUNCTION_ALIASES.get(function_name, function_name)
    
    # Get config or return defaults
    config = MODEL_CONFIG.get(actual_name, {})
    
    # Merge with defaults
    default_config = {
        "model": "gpt-4.1",
        "max_tokens": 4000,
        "temperature": 0.7,
        "response_format": None,
    }
    
    return {**default_config, **config}


def get_model(function_name: str) -> str:
    """Get model name for function"""
    config = get_model_config(function_name)
    return config.get("model", "gpt-4.1")


def get_max_tokens(function_name: str) -> int:
    """Get max tokens for function"""
    config = get_model_config(function_name)
    return config.get("max_tokens", 4000)


def get_temperature(function_name: str) -> float:
    """Get temperature for function"""
    config = get_model_config(function_name)
    return config.get("temperature", 0.7)

