"""Bridge factory — instantiates the right bridge for a provider type."""

from __future__ import annotations

import aiohttp

from backend.bridge.base import BaseBridge
from backend.bridge.openai_bridge import OpenAIBridge
from backend.bridge.anthropic_bridge import AnthropicBridge
from backend.config import ProviderConfig


def create_bridge(provider: ProviderConfig, session: aiohttp.ClientSession) -> BaseBridge:
    """Create the appropriate bridge for a provider type."""
    bridges = {
        "openai": OpenAIBridge,
        "openai-compatible": OpenAIBridge,
        "anthropic": AnthropicBridge,
    }

    bridge_cls = bridges.get(provider.type)
    if bridge_cls is None:
        raise ValueError(
            f"Unsupported provider type '{provider.type}'. "
            f"Supported: {', '.join(bridges.keys())}"
        )

    return bridge_cls(provider, session)
