from __future__ import annotations

from typing import Any

from langchain_anthropic import ChatAnthropic

from cleveragents.providers.llm.langchain_chat_provider import LangChainChatProvider


class AnthropicChatProvider(LangChainChatProvider):
    """Concrete provider adapter for Anthropic Claude models."""

    def __init__(
        self,
        *,
        api_key: str,
        model: str = "claude-sonnet-4-20250514",
        max_retries: int = 3,
        **llm_kwargs: Any,
    ) -> None:
        if not api_key:
            raise ValueError("Anthropic API key is required")

        def factory(resolved_model: str) -> ChatAnthropic:
            kwargs: dict[str, Any] = {"model": resolved_model, "api_key": api_key}
            if llm_kwargs:
                kwargs.update(llm_kwargs)
            return ChatAnthropic(**kwargs)

        super().__init__(
            name="anthropic",
            model_id=model,
            llm_factory=factory,
            max_retries=max_retries,
            supports_streaming=True,
        )
