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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.agent_event import AgentEvent
from ..types.agent_key import AgentKey
from ..types.agent_session_key import AgentSessionKey
from ..types.components_schemas_agent_text_input import ComponentsSchemasAgentTextInput
from .raw_client import AsyncRawAgentEventsClient, RawAgentEventsClient
from .types.agent_events_create_response import AgentEventsCreateResponse
from .types.agent_events_create_stream_response import AgentEventsCreateStreamResponse

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


class AgentEventsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAgentEventsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawAgentEventsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawAgentEventsClient
        """
        return self._raw_client

    def list(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[AgentEvent]:
        """
        List all events in a specific agent session, with optional pagination.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent.

        session_key : AgentSessionKey
            The unique key of the session to list events for.

        limit : typing.Optional[int]
            The maximum number of events to return in the list.

        page_key : typing.Optional[str]
            Used to retrieve the next page of events after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        SyncPager[AgentEvent]
            List of events in the session.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        response = client.agent_events.list(
            agent_key="customer_support",
            session_key="customer_support_chat",
        )
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        return self._raw_client.list(
            agent_key,
            session_key,
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )

    def create_stream(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        messages: typing.Sequence[ComponentsSchemasAgentTextInput],
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[AgentEventsCreateStreamResponse]:
        """
        Create a new input to an agent to interact with it.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent.

        session_key : AgentSessionKey
            The unique key of the session to create an input in.

        messages : typing.Sequence[ComponentsSchemasAgentTextInput]
            List of inputs that make up this event.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Yields
        ------
        typing.Iterator[AgentEventsCreateStreamResponse]


        Examples
        --------
        from vectara import AgentTextInput, Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        response = client.agent_events.create_stream(
            agent_key="customer_support",
            session_key="customer_support_chat",
            messages=[
                AgentTextInput(
                    content="I need help with my widget installation",
                )
            ],
        )
        for chunk in response:
            yield chunk
        """
        with self._raw_client.create_stream(
            agent_key,
            session_key,
            messages=messages,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        ) as r:
            yield from r.data

    def create(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        messages: typing.Sequence[ComponentsSchemasAgentTextInput],
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentEventsCreateResponse:
        """
        Create a new input to an agent to interact with it.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent.

        session_key : AgentSessionKey
            The unique key of the session to create an input in.

        messages : typing.Sequence[ComponentsSchemasAgentTextInput]
            List of inputs that make up this event.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        AgentEventsCreateResponse


        Examples
        --------
        from vectara import AgentTextInput, Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.agent_events.create(
            agent_key="customer_support",
            session_key="customer_support_chat",
            messages=[
                AgentTextInput(
                    content="I need help with my widget installation",
                )
            ],
        )
        """
        _response = self._raw_client.create(
            agent_key,
            session_key,
            messages=messages,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def get(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        event_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentEvent:
        """
        Retrieve the details of a specific event within an agent session.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent.

        session_key : AgentSessionKey
            The unique key of the session.

        event_id : str
            The unique identifier of the event to retrieve.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        AgentEvent
            The requested event details.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.agent_events.get(
            agent_key="customer_support",
            session_key="customer_support_chat",
            event_id="aev_user_001",
        )
        """
        _response = self._raw_client.get(
            agent_key,
            session_key,
            event_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data


class AsyncAgentEventsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAgentEventsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawAgentEventsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawAgentEventsClient
        """
        return self._raw_client

    async def list(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[AgentEvent]:
        """
        List all events in a specific agent session, with optional pagination.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent.

        session_key : AgentSessionKey
            The unique key of the session to list events for.

        limit : typing.Optional[int]
            The maximum number of events to return in the list.

        page_key : typing.Optional[str]
            Used to retrieve the next page of events after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        AsyncPager[AgentEvent]
            List of events in the session.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            response = await client.agent_events.list(
                agent_key="customer_support",
                session_key="customer_support_chat",
            )
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page


        asyncio.run(main())
        """
        return await self._raw_client.list(
            agent_key,
            session_key,
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )

    async def create_stream(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        messages: typing.Sequence[ComponentsSchemasAgentTextInput],
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[AgentEventsCreateStreamResponse]:
        """
        Create a new input to an agent to interact with it.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent.

        session_key : AgentSessionKey
            The unique key of the session to create an input in.

        messages : typing.Sequence[ComponentsSchemasAgentTextInput]
            List of inputs that make up this event.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Yields
        ------
        typing.AsyncIterator[AgentEventsCreateStreamResponse]


        Examples
        --------
        import asyncio

        from vectara import AgentTextInput, AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            response = await client.agent_events.create_stream(
                agent_key="customer_support",
                session_key="customer_support_chat",
                messages=[
                    AgentTextInput(
                        content="I need help with my widget installation",
                    )
                ],
            )
            async for chunk in response:
                yield chunk


        asyncio.run(main())
        """
        async with self._raw_client.create_stream(
            agent_key,
            session_key,
            messages=messages,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        ) as r:
            async for _chunk in r.data:
                yield _chunk

    async def create(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        messages: typing.Sequence[ComponentsSchemasAgentTextInput],
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentEventsCreateResponse:
        """
        Create a new input to an agent to interact with it.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent.

        session_key : AgentSessionKey
            The unique key of the session to create an input in.

        messages : typing.Sequence[ComponentsSchemasAgentTextInput]
            List of inputs that make up this event.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        AgentEventsCreateResponse


        Examples
        --------
        import asyncio

        from vectara import AgentTextInput, AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.agent_events.create(
                agent_key="customer_support",
                session_key="customer_support_chat",
                messages=[
                    AgentTextInput(
                        content="I need help with my widget installation",
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            agent_key,
            session_key,
            messages=messages,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        event_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentEvent:
        """
        Retrieve the details of a specific event within an agent session.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent.

        session_key : AgentSessionKey
            The unique key of the session.

        event_id : str
            The unique identifier of the event to retrieve.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        AgentEvent
            The requested event details.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.agent_events.get(
                agent_key="customer_support",
                session_key="customer_support_chat",
                event_id="aev_user_001",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(
            agent_key,
            session_key,
            event_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data
