# 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_key import AgentKey
from ..types.agent_session import AgentSession
from ..types.agent_session_key import AgentSessionKey
from .raw_client import AsyncRawAgentSessionsClient, RawAgentSessionsClient

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


class AgentSessionsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAgentSessionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAgentSessionsClient
        """
        return self._raw_client

    def list(
        self,
        agent_key: AgentKey,
        *,
        filter: typing.Optional[str] = None,
        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[AgentSession]:
        """
        List all agent sessions for a specific agent, with optional filtering and pagination.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent to list sessions for.

        filter : typing.Optional[str]
            A regular expression against session names and descriptions to filter the results.

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

        page_key : typing.Optional[str]
            Used to retrieve the next page of sessions 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[AgentSession]
            List of available agent sessions.

        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_sessions.list(
            agent_key="customer_support",
            filter="support.*",
        )
        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,
            filter=filter,
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )

    def create(
        self,
        agent_key: AgentKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        key: typing.Optional[AgentSessionKey] = OMIT,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        tti_minutes: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentSession:
        """
        Create a new session for interacting with an agent. Sessions maintain conversation context.

        Parameters
        ----------
        agent_key : AgentKey
            The unique key of the agent to create a session for.

        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.

        key : typing.Optional[AgentSessionKey]
            A user provided key that uniquely identifies this session. If not provided, one will be auto-generated based on the session name.

        name : typing.Optional[str]
            Human-readable name for the session.

        description : typing.Optional[str]
            Optional description of the session purpose or context.

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arbitrary metadata associated with the session.

        enabled : typing.Optional[bool]
            Whether the session should be enabled upon creation.

        tti_minutes : typing.Optional[int]
            Time-to-idle in minutes for the session. If no events occur in the session for this duration, the session will be automatically deleted. If set to 0, the session will not expire.

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

        Returns
        -------
        AgentSession
            The agent session has been created successfully.

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

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.agent_sessions.create(
            agent_key="customer_support",
        )
        """
        _response = self._raw_client.create(
            agent_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            key=key,
            name=name,
            description=description,
            metadata=metadata,
            enabled=enabled,
            tti_minutes=tti_minutes,
            request_options=request_options,
        )
        return _response.data

    def get(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentSession:
        """
        Retrieve the details of a specific agent session by its ID, including session configuration.

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

        session_key : AgentSessionKey
            The unique key of the session 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
        -------
        AgentSession
            The requested agent session 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_sessions.get(
            agent_key="customer_support",
            session_key="customer_support_chat",
        )
        """
        _response = self._raw_client.get(
            agent_key,
            session_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def delete(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Permanently delete an agent session. This action cannot be undone.

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

        session_key : AgentSessionKey
            The unique key of the session to delete.

        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
        -------
        None

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

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

    def update(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        tti_minutes: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentSession:
        """
        Update an existing agent session's configuration and metadata.

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

        session_key : AgentSessionKey
            The unique key of the session to update.

        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.

        name : typing.Optional[str]
            Human-readable name for the session.

        description : typing.Optional[str]
            Optional description of the session purpose or context.

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arbitrary metadata associated with the session.

        enabled : typing.Optional[bool]
            Whether the session is enabled.

        tti_minutes : typing.Optional[int]
            Time-to-idle in minutes for the session. If no events occur in the session for this duration, the session will be automatically deleted. If set to 0, the session will not expire.

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

        Returns
        -------
        AgentSession
            The agent session has been updated successfully.

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

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.agent_sessions.update(
            agent_key="customer_support",
            session_key="customer_support_chat",
        )
        """
        _response = self._raw_client.update(
            agent_key,
            session_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            name=name,
            description=description,
            metadata=metadata,
            enabled=enabled,
            tti_minutes=tti_minutes,
            request_options=request_options,
        )
        return _response.data


class AsyncAgentSessionsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAgentSessionsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAgentSessionsClient
        """
        return self._raw_client

    async def list(
        self,
        agent_key: AgentKey,
        *,
        filter: typing.Optional[str] = None,
        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[AgentSession]:
        """
        List all agent sessions for a specific agent, with optional filtering and pagination.

        Parameters
        ----------
        agent_key : AgentKey
            The unique identifier of the agent to list sessions for.

        filter : typing.Optional[str]
            A regular expression against session names and descriptions to filter the results.

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

        page_key : typing.Optional[str]
            Used to retrieve the next page of sessions 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[AgentSession]
            List of available agent sessions.

        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_sessions.list(
                agent_key="customer_support",
                filter="support.*",
            )
            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,
            filter=filter,
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )

    async def create(
        self,
        agent_key: AgentKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        key: typing.Optional[AgentSessionKey] = OMIT,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        tti_minutes: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentSession:
        """
        Create a new session for interacting with an agent. Sessions maintain conversation context.

        Parameters
        ----------
        agent_key : AgentKey
            The unique key of the agent to create a session for.

        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.

        key : typing.Optional[AgentSessionKey]
            A user provided key that uniquely identifies this session. If not provided, one will be auto-generated based on the session name.

        name : typing.Optional[str]
            Human-readable name for the session.

        description : typing.Optional[str]
            Optional description of the session purpose or context.

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arbitrary metadata associated with the session.

        enabled : typing.Optional[bool]
            Whether the session should be enabled upon creation.

        tti_minutes : typing.Optional[int]
            Time-to-idle in minutes for the session. If no events occur in the session for this duration, the session will be automatically deleted. If set to 0, the session will not expire.

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

        Returns
        -------
        AgentSession
            The agent session has been created successfully.

        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_sessions.create(
                agent_key="customer_support",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            agent_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            key=key,
            name=name,
            description=description,
            metadata=metadata,
            enabled=enabled,
            tti_minutes=tti_minutes,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentSession:
        """
        Retrieve the details of a specific agent session by its ID, including session configuration.

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

        session_key : AgentSessionKey
            The unique key of the session 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
        -------
        AgentSession
            The requested agent session 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_sessions.get(
                agent_key="customer_support",
                session_key="customer_support_chat",
            )


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

    async def delete(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Permanently delete an agent session. This action cannot be undone.

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

        session_key : AgentSessionKey
            The unique key of the session to delete.

        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
        -------
        None

        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_sessions.delete(
                agent_key="customer_support",
                session_key="customer_support_chat",
            )


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

    async def update(
        self,
        agent_key: AgentKey,
        session_key: AgentSessionKey,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
        enabled: typing.Optional[bool] = OMIT,
        tti_minutes: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AgentSession:
        """
        Update an existing agent session's configuration and metadata.

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

        session_key : AgentSessionKey
            The unique key of the session to update.

        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.

        name : typing.Optional[str]
            Human-readable name for the session.

        description : typing.Optional[str]
            Optional description of the session purpose or context.

        metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
            Arbitrary metadata associated with the session.

        enabled : typing.Optional[bool]
            Whether the session is enabled.

        tti_minutes : typing.Optional[int]
            Time-to-idle in minutes for the session. If no events occur in the session for this duration, the session will be automatically deleted. If set to 0, the session will not expire.

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

        Returns
        -------
        AgentSession
            The agent session has been updated successfully.

        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_sessions.update(
                agent_key="customer_support",
                session_key="customer_support_chat",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            agent_key,
            session_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            name=name,
            description=description,
            metadata=metadata,
            enabled=enabled,
            tti_minutes=tti_minutes,
            request_options=request_options,
        )
        return _response.data
