# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ...core.api_error import ApiError
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.pydantic_utilities import pydantic_v1
from ...core.request_options import RequestOptions
from ...errors.unprocessable_entity_error import UnprocessableEntityError
from ...types.research_agent_response import ResearchAgentResponse

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class ResearchClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def invoke(
        self,
        *,
        config: typing.Dict[str, typing.Any],
        messages: typing.Sequence[typing.Dict[str, typing.Any]],
        request_options: typing.Optional[RequestOptions] = None
    ) -> ResearchAgentResponse:
        """
        Coming soon! Conduct research using web and other sources.

        Parameters
        ----------
        config : typing.Dict[str, typing.Any]
            Configuration for the research agent including search parameters and sources

        messages : typing.Sequence[typing.Dict[str, typing.Any]]
            The messages to send to the research agent

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ResearchAgentResponse
            Successful Response

        Examples
        --------
        from athena.client import Athena

        client = Athena(
            api_key="YOUR_API_KEY",
        )
        client.agents.research.invoke(
            config={"key": "value"},
            messages=[{"key": "value"}],
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/v0/agents/research/invoke",
            method="POST",
            json={"config": config, "messages": messages},
            request_options=request_options,
            omit=OMIT,
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(ResearchAgentResponse, _response.json())  # type: ignore
        if _response.status_code == 422:
            raise UnprocessableEntityError(pydantic_v1.parse_obj_as(typing.Any, _response.json()))  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncResearchClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def invoke(
        self,
        *,
        config: typing.Dict[str, typing.Any],
        messages: typing.Sequence[typing.Dict[str, typing.Any]],
        request_options: typing.Optional[RequestOptions] = None
    ) -> ResearchAgentResponse:
        """
        Coming soon! Conduct research using web and other sources.

        Parameters
        ----------
        config : typing.Dict[str, typing.Any]
            Configuration for the research agent including search parameters and sources

        messages : typing.Sequence[typing.Dict[str, typing.Any]]
            The messages to send to the research agent

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ResearchAgentResponse
            Successful Response

        Examples
        --------
        from athena.client import AsyncAthena

        client = AsyncAthena(
            api_key="YOUR_API_KEY",
        )
        await client.agents.research.invoke(
            config={"key": "value"},
            messages=[{"key": "value"}],
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/v0/agents/research/invoke",
            method="POST",
            json={"config": config, "messages": messages},
            request_options=request_options,
            omit=OMIT,
        )
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(ResearchAgentResponse, _response.json())  # type: ignore
        if _response.status_code == 422:
            raise UnprocessableEntityError(pydantic_v1.parse_obj_as(typing.Any, _response.json()))  # type: ignore
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
