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

import typing

from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.request_options import RequestOptions
from ...types.get_conversation_users_page_response_model import GetConversationUsersPageResponseModel
from ...types.users_sort_by import UsersSortBy
from .raw_client import AsyncRawUsersClient, RawUsersClient


class UsersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawUsersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawUsersClient
        """
        return self._raw_client

    def list(
        self,
        *,
        agent_id: typing.Optional[str] = None,
        branch_id: typing.Optional[str] = None,
        call_start_before_unix: typing.Optional[int] = None,
        call_start_after_unix: typing.Optional[int] = None,
        search: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        sort_by: typing.Optional[UsersSortBy] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetConversationUsersPageResponseModel:
        """
        Get distinct users from conversations with pagination.

        Parameters
        ----------
        agent_id : typing.Optional[str]
            Agent id (agent_…) or speech engine external id (seng_), resolved to the same underlying resource.

        branch_id : typing.Optional[str]
            Filter conversations by branch ID.

        call_start_before_unix : typing.Optional[int]
            Unix timestamp (in seconds) to filter conversations up to this start date.

        call_start_after_unix : typing.Optional[int]
            Unix timestamp (in seconds) to filter conversations after to this start date.

        search : typing.Optional[str]
            Search/filter by user ID (exact match).

        page_size : typing.Optional[int]
            How many users to return at maximum. Defaults to 30.

        sort_by : typing.Optional[UsersSortBy]
            The field to sort the results by. Defaults to last_contact_unix_secs.

        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

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

        Returns
        -------
        GetConversationUsersPageResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.users.list(
            agent_id="agent_id",
            branch_id="branch_id",
            call_start_before_unix=1,
            call_start_after_unix=1,
            search="search",
            page_size=1,
            sort_by="last_contact_unix_secs",
            cursor="cursor",
        )
        """
        _response = self._raw_client.list(
            agent_id=agent_id,
            branch_id=branch_id,
            call_start_before_unix=call_start_before_unix,
            call_start_after_unix=call_start_after_unix,
            search=search,
            page_size=page_size,
            sort_by=sort_by,
            cursor=cursor,
            request_options=request_options,
        )
        return _response.data


class AsyncUsersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawUsersClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawUsersClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        agent_id: typing.Optional[str] = None,
        branch_id: typing.Optional[str] = None,
        call_start_before_unix: typing.Optional[int] = None,
        call_start_after_unix: typing.Optional[int] = None,
        search: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        sort_by: typing.Optional[UsersSortBy] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetConversationUsersPageResponseModel:
        """
        Get distinct users from conversations with pagination.

        Parameters
        ----------
        agent_id : typing.Optional[str]
            Agent id (agent_…) or speech engine external id (seng_), resolved to the same underlying resource.

        branch_id : typing.Optional[str]
            Filter conversations by branch ID.

        call_start_before_unix : typing.Optional[int]
            Unix timestamp (in seconds) to filter conversations up to this start date.

        call_start_after_unix : typing.Optional[int]
            Unix timestamp (in seconds) to filter conversations after to this start date.

        search : typing.Optional[str]
            Search/filter by user ID (exact match).

        page_size : typing.Optional[int]
            How many users to return at maximum. Defaults to 30.

        sort_by : typing.Optional[UsersSortBy]
            The field to sort the results by. Defaults to last_contact_unix_secs.

        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

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

        Returns
        -------
        GetConversationUsersPageResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.users.list(
                agent_id="agent_id",
                branch_id="branch_id",
                call_start_before_unix=1,
                call_start_after_unix=1,
                search="search",
                page_size=1,
                sort_by="last_contact_unix_secs",
                cursor="cursor",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            agent_id=agent_id,
            branch_id=branch_id,
            call_start_before_unix=call_start_before_unix,
            call_start_after_unix=call_start_after_unix,
            search=search,
            page_size=page_size,
            sort_by=sort_by,
            cursor=cursor,
            request_options=request_options,
        )
        return _response.data
