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

from ...core.client_wrapper import SyncClientWrapper
from .raw_client import RawTeamMemberProfilesClient
import typing
from ...core.request_options import RequestOptions
from ...core.pagination import SyncPager
from ...types.team_member_booking_profile import TeamMemberBookingProfile
from ...types.list_team_member_booking_profiles_response import ListTeamMemberBookingProfilesResponse
from ...core.unchecked_base_model import construct_type
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...types.get_team_member_booking_profile_response import GetTeamMemberBookingProfileResponse
from ...core.client_wrapper import AsyncClientWrapper
from .raw_client import AsyncRawTeamMemberProfilesClient
from ...core.pagination import AsyncPager


class TeamMemberProfilesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawTeamMemberProfilesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawTeamMemberProfilesClient
        """
        return self._raw_client

    def list(
        self,
        *,
        bookable_only: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        location_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[TeamMemberBookingProfile]:
        """
        Lists booking profiles for team members.

        Parameters
        ----------
        bookable_only : typing.Optional[bool]
            Indicates whether to include only bookable team members in the returned result (`true`) or not (`false`).

        limit : typing.Optional[int]
            The maximum number of results to return in a paged response.

        cursor : typing.Optional[str]
            The pagination cursor from the preceding response to return the next page of the results. Do not set this when retrieving the first page of the results.

        location_id : typing.Optional[str]
            Indicates whether to include only team members enabled at the given location in the returned result.

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

        Returns
        -------
        SyncPager[TeamMemberBookingProfile]
            Success

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

        client = Square(
            token="YOUR_TOKEN",
        )
        response = client.bookings.team_member_profiles.list()
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        _response = self._raw_client._client_wrapper.httpx_client.request(
            "v2/bookings/team-member-booking-profiles",
            method="GET",
            params={
                "bookable_only": bookable_only,
                "limit": limit,
                "cursor": cursor,
                "location_id": location_id,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    ListTeamMemberBookingProfilesResponse,
                    construct_type(
                        type_=ListTeamMemberBookingProfilesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                _parsed_next = _parsed_response.cursor
                _has_next = _parsed_next is not None and _parsed_next != ""
                _get_next = lambda: self.list(
                    bookable_only=bookable_only,
                    limit=limit,
                    cursor=_parsed_next,
                    location_id=location_id,
                    request_options=request_options,
                )
                _items = _parsed_response.team_member_booking_profiles
                return SyncPager(has_next=_has_next, items=_items, get_next=_get_next)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def get(
        self, team_member_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetTeamMemberBookingProfileResponse:
        """
        Retrieves a team member's booking profile.

        Parameters
        ----------
        team_member_id : str
            The ID of the team member to retrieve.

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

        Returns
        -------
        GetTeamMemberBookingProfileResponse
            Success

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

        client = Square(
            token="YOUR_TOKEN",
        )
        client.bookings.team_member_profiles.get(
            team_member_id="team_member_id",
        )
        """
        response = self._raw_client.get(team_member_id, request_options=request_options)
        return response.data


class AsyncTeamMemberProfilesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawTeamMemberProfilesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawTeamMemberProfilesClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        bookable_only: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        location_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[TeamMemberBookingProfile]:
        """
        Lists booking profiles for team members.

        Parameters
        ----------
        bookable_only : typing.Optional[bool]
            Indicates whether to include only bookable team members in the returned result (`true`) or not (`false`).

        limit : typing.Optional[int]
            The maximum number of results to return in a paged response.

        cursor : typing.Optional[str]
            The pagination cursor from the preceding response to return the next page of the results. Do not set this when retrieving the first page of the results.

        location_id : typing.Optional[str]
            Indicates whether to include only team members enabled at the given location in the returned result.

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

        Returns
        -------
        AsyncPager[TeamMemberBookingProfile]
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.bookings.team_member_profiles.list()
            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())
        """
        _response = await self._raw_client._client_wrapper.httpx_client.request(
            "v2/bookings/team-member-booking-profiles",
            method="GET",
            params={
                "bookable_only": bookable_only,
                "limit": limit,
                "cursor": cursor,
                "location_id": location_id,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    ListTeamMemberBookingProfilesResponse,
                    construct_type(
                        type_=ListTeamMemberBookingProfilesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                _parsed_next = _parsed_response.cursor
                _has_next = _parsed_next is not None and _parsed_next != ""
                _get_next = lambda: self.list(
                    bookable_only=bookable_only,
                    limit=limit,
                    cursor=_parsed_next,
                    location_id=location_id,
                    request_options=request_options,
                )
                _items = _parsed_response.team_member_booking_profiles
                return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def get(
        self, team_member_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetTeamMemberBookingProfileResponse:
        """
        Retrieves a team member's booking profile.

        Parameters
        ----------
        team_member_id : str
            The ID of the team member to retrieve.

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

        Returns
        -------
        GetTeamMemberBookingProfileResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.bookings.team_member_profiles.get(
                team_member_id="team_member_id",
            )


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