# 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 .raw_client import AsyncRawLogsClient, RawLogsClient
from .types.get_conversation_id_response import GetConversationIdResponse
from .types.get_conversation_request_call_types import GetConversationRequestCallTypes
from .types.get_conversation_response import GetConversationResponse
from .types.post_conversation_search_response import PostConversationSearchResponse

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


class LogsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawLogsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawLogsClient
        """
        return self._raw_client

    def get_all_conversation_logs(
        self,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        agent_ids: typing.Optional[str] = None,
        campaign_ids: typing.Optional[str] = None,
        call_types: typing.Optional[GetConversationRequestCallTypes] = None,
        search: typing.Optional[str] = None,
        status_filter: typing.Optional[str] = None,
        disconnect_reason_filter: typing.Optional[str] = None,
        call_attempt_filter: typing.Optional[str] = None,
        duration_filter: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetConversationResponse:
        """
        Retrieve paginated conversation logs with support for various filters. Returns call logs for agents belonging to the authenticated user's organization.

        Parameters
        ----------
        page : typing.Optional[int]
            Page number for pagination

        limit : typing.Optional[int]
            Number of items per page

        agent_ids : typing.Optional[str]
            Comma-separated list of agent IDs to filter by

        campaign_ids : typing.Optional[str]
            Comma-separated list of campaign IDs to filter by

        call_types : typing.Optional[GetConversationRequestCallTypes]
            Comma-separated list of call types to filter by

        search : typing.Optional[str]
            Search query to filter by callId, fromNumber, or toNumber

        status_filter : typing.Optional[str]
            Comma-separated list of call statuses to filter by.
            Available statuses: pending, in_progress, completed, failed, no_answer, cancelled, busy

        disconnect_reason_filter : typing.Optional[str]
            Comma-separated list of disconnect reasons to filter by.
            Available reasons: user_hangup, agent_hangup, connection_error, timeout, system_error, transfer_complete

        call_attempt_filter : typing.Optional[str]
            Comma-separated list of call attempt types to filter by.
            Available filters: initial (first attempt calls), retry (retry attempt calls), all (all calls)

        duration_filter : typing.Optional[str]
            Comma-separated list of duration ranges to filter by.
            Available ranges: 0-30 (0-30 seconds), 30-60 (30-60 seconds), 1-5 (1-5 minutes), 5+ (more than 5 minutes)

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

        Returns
        -------
        GetConversationResponse
            Successful response

        Examples
        --------
        from smallestai import SmallestAI

        client = SmallestAI(
            token="YOUR_TOKEN",
        )
        client.atoms.logs.get_all_conversation_logs(
            agent_ids="60d0fe4f5311236168a109ca,60d0fe4f5311236168a109cb",
            campaign_ids="60d0fe4f5311236168a109ca,60d0fe4f5311236168a109cb",
            search="+1234567890",
            status_filter="completed,failed",
            disconnect_reason_filter="user_hangup,agent_hangup",
            call_attempt_filter="initial",
            duration_filter="0-30,30-60",
        )
        """
        _response = self._raw_client.get_all_conversation_logs(
            page=page,
            limit=limit,
            agent_ids=agent_ids,
            campaign_ids=campaign_ids,
            call_types=call_types,
            search=search,
            status_filter=status_filter,
            disconnect_reason_filter=disconnect_reason_filter,
            call_attempt_filter=call_attempt_filter,
            duration_filter=duration_filter,
            request_options=request_options,
        )
        return _response.data

    def search_conversation_logs_by_call_i_ds(
        self, *, call_ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> PostConversationSearchResponse:
        """
        Fetch specific conversation logs by their callIds. This endpoint allows you to retrieve up to 100 specific calls at once.
        Only returns calls that belong to agents in your organization (security check enforced).
        Unlike the GET /conversation endpoint, this endpoint can also return retry calls (non-root calls).

        Parameters
        ----------
        call_ids : typing.Sequence[str]
            Array of callIds to fetch

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

        Returns
        -------
        PostConversationSearchResponse
            Successful response

        Examples
        --------
        from smallestai import SmallestAI

        client = SmallestAI(
            token="YOUR_TOKEN",
        )
        client.atoms.logs.search_conversation_logs_by_call_i_ds(
            call_ids=["CALL-1737000000000-abc123", "CALL-1737000000001-def456"],
        )
        """
        _response = self._raw_client.search_conversation_logs_by_call_i_ds(
            call_ids=call_ids, request_options=request_options
        )
        return _response.data

    def get_conversation_log_by_id(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetConversationIdResponse:
        """
        Retrieve detailed information about a specific conversation including transcript, events, and latency metrics.

        Parameters
        ----------
        id : str
            The callId of the conversation. You can get the callId from the conversation logs endpoint.

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

        Returns
        -------
        GetConversationIdResponse
            Successful response

        Examples
        --------
        from smallestai import SmallestAI

        client = SmallestAI(
            token="YOUR_TOKEN",
        )
        client.atoms.logs.get_conversation_log_by_id(
            id="CALL-1737000000000-abc123",
        )
        """
        _response = self._raw_client.get_conversation_log_by_id(id, request_options=request_options)
        return _response.data


class AsyncLogsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawLogsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawLogsClient
        """
        return self._raw_client

    async def get_all_conversation_logs(
        self,
        *,
        page: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        agent_ids: typing.Optional[str] = None,
        campaign_ids: typing.Optional[str] = None,
        call_types: typing.Optional[GetConversationRequestCallTypes] = None,
        search: typing.Optional[str] = None,
        status_filter: typing.Optional[str] = None,
        disconnect_reason_filter: typing.Optional[str] = None,
        call_attempt_filter: typing.Optional[str] = None,
        duration_filter: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetConversationResponse:
        """
        Retrieve paginated conversation logs with support for various filters. Returns call logs for agents belonging to the authenticated user's organization.

        Parameters
        ----------
        page : typing.Optional[int]
            Page number for pagination

        limit : typing.Optional[int]
            Number of items per page

        agent_ids : typing.Optional[str]
            Comma-separated list of agent IDs to filter by

        campaign_ids : typing.Optional[str]
            Comma-separated list of campaign IDs to filter by

        call_types : typing.Optional[GetConversationRequestCallTypes]
            Comma-separated list of call types to filter by

        search : typing.Optional[str]
            Search query to filter by callId, fromNumber, or toNumber

        status_filter : typing.Optional[str]
            Comma-separated list of call statuses to filter by.
            Available statuses: pending, in_progress, completed, failed, no_answer, cancelled, busy

        disconnect_reason_filter : typing.Optional[str]
            Comma-separated list of disconnect reasons to filter by.
            Available reasons: user_hangup, agent_hangup, connection_error, timeout, system_error, transfer_complete

        call_attempt_filter : typing.Optional[str]
            Comma-separated list of call attempt types to filter by.
            Available filters: initial (first attempt calls), retry (retry attempt calls), all (all calls)

        duration_filter : typing.Optional[str]
            Comma-separated list of duration ranges to filter by.
            Available ranges: 0-30 (0-30 seconds), 30-60 (30-60 seconds), 1-5 (1-5 minutes), 5+ (more than 5 minutes)

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

        Returns
        -------
        GetConversationResponse
            Successful response

        Examples
        --------
        import asyncio

        from smallestai import AsyncSmallestAI

        client = AsyncSmallestAI(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.atoms.logs.get_all_conversation_logs(
                agent_ids="60d0fe4f5311236168a109ca,60d0fe4f5311236168a109cb",
                campaign_ids="60d0fe4f5311236168a109ca,60d0fe4f5311236168a109cb",
                search="+1234567890",
                status_filter="completed,failed",
                disconnect_reason_filter="user_hangup,agent_hangup",
                call_attempt_filter="initial",
                duration_filter="0-30,30-60",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_all_conversation_logs(
            page=page,
            limit=limit,
            agent_ids=agent_ids,
            campaign_ids=campaign_ids,
            call_types=call_types,
            search=search,
            status_filter=status_filter,
            disconnect_reason_filter=disconnect_reason_filter,
            call_attempt_filter=call_attempt_filter,
            duration_filter=duration_filter,
            request_options=request_options,
        )
        return _response.data

    async def search_conversation_logs_by_call_i_ds(
        self, *, call_ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> PostConversationSearchResponse:
        """
        Fetch specific conversation logs by their callIds. This endpoint allows you to retrieve up to 100 specific calls at once.
        Only returns calls that belong to agents in your organization (security check enforced).
        Unlike the GET /conversation endpoint, this endpoint can also return retry calls (non-root calls).

        Parameters
        ----------
        call_ids : typing.Sequence[str]
            Array of callIds to fetch

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

        Returns
        -------
        PostConversationSearchResponse
            Successful response

        Examples
        --------
        import asyncio

        from smallestai import AsyncSmallestAI

        client = AsyncSmallestAI(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.atoms.logs.search_conversation_logs_by_call_i_ds(
                call_ids=["CALL-1737000000000-abc123", "CALL-1737000000001-def456"],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.search_conversation_logs_by_call_i_ds(
            call_ids=call_ids, request_options=request_options
        )
        return _response.data

    async def get_conversation_log_by_id(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetConversationIdResponse:
        """
        Retrieve detailed information about a specific conversation including transcript, events, and latency metrics.

        Parameters
        ----------
        id : str
            The callId of the conversation. You can get the callId from the conversation logs endpoint.

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

        Returns
        -------
        GetConversationIdResponse
            Successful response

        Examples
        --------
        import asyncio

        from smallestai import AsyncSmallestAI

        client = AsyncSmallestAI(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.atoms.logs.get_conversation_log_by_id(
                id="CALL-1737000000000-abc123",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_conversation_log_by_id(id, request_options=request_options)
        return _response.data
