from __future__ import annotations

from typing import Any

from langchain_google_genai import ChatGoogleGenerativeAI

from cleveragents.providers.llm.langchain_chat_provider import LangChainChatProvider


class GoogleChatProvider(LangChainChatProvider):
    """Concrete provider adapter for Google Gemini chat models."""

    def __init__(
        self,
        *,
        api_key: str,
        model: str = "gemini-2.0-flash",
        max_retries: int = 3,
        **llm_kwargs: Any,
    ) -> None:
        if not api_key:
            raise ValueError("Google API key is required")

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

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