from ai.base import AIProvider, ClassificationResult
from ai.anthropic_provider import AnthropicProvider
from ai.openai_provider import OpenAIProvider
from ai.ollama_provider import OllamaProvider
from ai.lmstudio_provider import LMStudioProvider


def get_provider(settings: dict) -> AIProvider:
    active = settings.get("active_provider", "lmstudio")
    providers = settings.get("providers", {})
    cfg = providers.get(active, {})

    if active == "anthropic":
        return AnthropicProvider(
            api_key=cfg.get("api_key", ""),
            model=cfg.get("model", "claude-sonnet-4-6"),
        )
    elif active == "openai":
        return OpenAIProvider(
            api_key=cfg.get("api_key", ""),
            model=cfg.get("model", "gpt-4o"),
            base_url=cfg.get("base_url") or None,
        )
    elif active == "ollama":
        return OllamaProvider(
            base_url=cfg.get("base_url", "http://host.docker.internal:11434"),
            model=cfg.get("model", "llama3.2"),
        )
    elif active == "lmstudio":
        return LMStudioProvider(
            base_url=cfg.get("base_url", "http://host.docker.internal:1234"),
            model=cfg.get("model", "gemma-4-e4b-it"),
        )
    else:
        raise ValueError(f"Unknown AI provider: {active}")
