# 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.audience_count_only import AudienceCountOnly
from .raw_client import AsyncRawContactsClient, RawContactsClient

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


class ContactsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawContactsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawContactsClient
        """
        return self._raw_client

    def remove(
        self, *, id: str, contacts: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> AudienceCountOnly:
        """
        Remove contacts from an existing audience. This operation is idempotent.

        - Only removes contacts that exist in the audience
        - Contacts not in the audience are ignored

        Parameters
        ----------
        id : str
            Audience ID. This identifier is a string that always begins with the prefix `aud_`, for example: `aud_abc123`.

        contacts : typing.Sequence[str]
            Array of phone numbers (E.164 format) or contact IDs. <br><br>
            **Limit:** 1 min

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

        Returns
        -------
        AudienceCountOnly
            Successfully removed contacts from the audience.

        Examples
        --------
        from rcs import Pinnacle

        client = Pinnacle(
            api_key="YOUR_API_KEY",
        )
        client.audiences.contacts.remove(
            id="aud_abc123",
            contacts=["+12125551234", "co_def456"],
        )
        """
        _response = self._raw_client.remove(id=id, contacts=contacts, request_options=request_options)
        return _response.data

    def add(
        self, *, id: str, contacts: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> AudienceCountOnly:
        """
        Add contacts to an existing audience. This operation is additive and idempotent.

        - Phone numbers that don't exist will be auto-created as contacts
        - Duplicate adds are ignored
        - Contacts already in the audience are ignored

        Parameters
        ----------
        id : str
            Audience ID. This identifier is a string that always begins with the prefix `aud_`, for example: `aud_abc123`.

        contacts : typing.Sequence[str]
            Array of phone numbers (E.164 format) or contact IDs. <br><br>
            **Limit:** 1 min

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

        Returns
        -------
        AudienceCountOnly
            Successfully added contacts to the audience.

        Examples
        --------
        from rcs import Pinnacle

        client = Pinnacle(
            api_key="YOUR_API_KEY",
        )
        client.audiences.contacts.add(
            id="aud_abc123",
            contacts=["+12125551234", "co_def456", "+13105551234"],
        )
        """
        _response = self._raw_client.add(id=id, contacts=contacts, request_options=request_options)
        return _response.data


class AsyncContactsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawContactsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawContactsClient
        """
        return self._raw_client

    async def remove(
        self, *, id: str, contacts: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> AudienceCountOnly:
        """
        Remove contacts from an existing audience. This operation is idempotent.

        - Only removes contacts that exist in the audience
        - Contacts not in the audience are ignored

        Parameters
        ----------
        id : str
            Audience ID. This identifier is a string that always begins with the prefix `aud_`, for example: `aud_abc123`.

        contacts : typing.Sequence[str]
            Array of phone numbers (E.164 format) or contact IDs. <br><br>
            **Limit:** 1 min

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

        Returns
        -------
        AudienceCountOnly
            Successfully removed contacts from the audience.

        Examples
        --------
        import asyncio

        from rcs import AsyncPinnacle

        client = AsyncPinnacle(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.audiences.contacts.remove(
                id="aud_abc123",
                contacts=["+12125551234", "co_def456"],
            )


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

    async def add(
        self, *, id: str, contacts: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> AudienceCountOnly:
        """
        Add contacts to an existing audience. This operation is additive and idempotent.

        - Phone numbers that don't exist will be auto-created as contacts
        - Duplicate adds are ignored
        - Contacts already in the audience are ignored

        Parameters
        ----------
        id : str
            Audience ID. This identifier is a string that always begins with the prefix `aud_`, for example: `aud_abc123`.

        contacts : typing.Sequence[str]
            Array of phone numbers (E.164 format) or contact IDs. <br><br>
            **Limit:** 1 min

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

        Returns
        -------
        AudienceCountOnly
            Successfully added contacts to the audience.

        Examples
        --------
        import asyncio

        from rcs import AsyncPinnacle

        client = AsyncPinnacle(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.audiences.contacts.add(
                id="aud_abc123",
                contacts=["+12125551234", "co_def456", "+13105551234"],
            )


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