# 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.bulk_retrieve_channels_response import BulkRetrieveChannelsResponse
from ..types.channel import Channel
from ..types.channel_status import ChannelStatus
from ..types.list_channels_response import ListChannelsResponse
from ..types.reference_type import ReferenceType
from ..types.retrieve_channel_response import RetrieveChannelResponse
from .raw_client import AsyncRawChannelsClient, RawChannelsClient

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


class ChannelsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawChannelsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawChannelsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        reference_type: typing.Optional[ReferenceType] = None,
        reference_id: typing.Optional[str] = None,
        status: typing.Optional[ChannelStatus] = None,
        cursor: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Channel, ListChannelsResponse]:
        """


        Parameters
        ----------
        reference_type : typing.Optional[ReferenceType]
            Type of reference associated to channel

        reference_id : typing.Optional[str]
            id of reference associated to channel

        status : typing.Optional[ChannelStatus]
            Status of channel

        cursor : typing.Optional[str]
            Cursor to fetch the next result

        limit : typing.Optional[int]
            Maximum number of results to return.
            When not provided the returned results will be cap at 100 channels.

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

        Returns
        -------
        SyncPager[Channel, ListChannelsResponse]
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        response = client.channels.list(
            reference_type="UNKNOWN_TYPE",
            reference_id="reference_id",
            status="ACTIVE",
            cursor="cursor",
            limit=1,
        )
        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(
            reference_type=reference_type,
            reference_id=reference_id,
            status=status,
            cursor=cursor,
            limit=limit,
            request_options=request_options,
        )

    def bulk_retrieve(
        self, *, channel_ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> BulkRetrieveChannelsResponse:
        """


        Parameters
        ----------
        channel_ids : typing.Sequence[str]

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

        Returns
        -------
        BulkRetrieveChannelsResponse
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.channels.bulk_retrieve(
            channel_ids=["CH_9C03D0B59", "CH_6X139B5MN", "NOT_EXISTING"],
        )
        """
        _response = self._raw_client.bulk_retrieve(channel_ids=channel_ids, request_options=request_options)
        return _response.data

    def get(
        self, channel_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RetrieveChannelResponse:
        """


        Parameters
        ----------
        channel_id : str
            A channel id

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

        Returns
        -------
        RetrieveChannelResponse
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.channels.get(
            channel_id="channel_id",
        )
        """
        _response = self._raw_client.get(channel_id, request_options=request_options)
        return _response.data


class AsyncChannelsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawChannelsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawChannelsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        reference_type: typing.Optional[ReferenceType] = None,
        reference_id: typing.Optional[str] = None,
        status: typing.Optional[ChannelStatus] = None,
        cursor: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Channel, ListChannelsResponse]:
        """


        Parameters
        ----------
        reference_type : typing.Optional[ReferenceType]
            Type of reference associated to channel

        reference_id : typing.Optional[str]
            id of reference associated to channel

        status : typing.Optional[ChannelStatus]
            Status of channel

        cursor : typing.Optional[str]
            Cursor to fetch the next result

        limit : typing.Optional[int]
            Maximum number of results to return.
            When not provided the returned results will be cap at 100 channels.

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

        Returns
        -------
        AsyncPager[Channel, ListChannelsResponse]
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.channels.list(
                reference_type="UNKNOWN_TYPE",
                reference_id="reference_id",
                status="ACTIVE",
                cursor="cursor",
                limit=1,
            )
            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(
            reference_type=reference_type,
            reference_id=reference_id,
            status=status,
            cursor=cursor,
            limit=limit,
            request_options=request_options,
        )

    async def bulk_retrieve(
        self, *, channel_ids: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None
    ) -> BulkRetrieveChannelsResponse:
        """


        Parameters
        ----------
        channel_ids : typing.Sequence[str]

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

        Returns
        -------
        BulkRetrieveChannelsResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.channels.bulk_retrieve(
                channel_ids=["CH_9C03D0B59", "CH_6X139B5MN", "NOT_EXISTING"],
            )


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

    async def get(
        self, channel_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RetrieveChannelResponse:
        """


        Parameters
        ----------
        channel_id : str
            A channel id

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

        Returns
        -------
        RetrieveChannelResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.channels.get(
                channel_id="channel_id",
            )


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