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

from ...core.client_wrapper import SyncClientWrapper
from .raw_client import RawEmployeeWagesClient
import typing
from ...core.request_options import RequestOptions
from ...core.pagination import SyncPager
from ...types.employee_wage import EmployeeWage
from ...types.list_employee_wages_response import ListEmployeeWagesResponse
from ...core.unchecked_base_model import construct_type
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...types.get_employee_wage_response import GetEmployeeWageResponse
from ...core.client_wrapper import AsyncClientWrapper
from .raw_client import AsyncRawEmployeeWagesClient
from ...core.pagination import AsyncPager


class EmployeeWagesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawEmployeeWagesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawEmployeeWagesClient
        """
        return self._raw_client

    def list(
        self,
        *,
        employee_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[EmployeeWage]:
        """
        Returns a paginated list of `EmployeeWage` instances for a business.

        Parameters
        ----------
        employee_id : typing.Optional[str]
            Filter the returned wages to only those that are associated with the specified employee.

        limit : typing.Optional[int]
            The maximum number of `EmployeeWage` results to return per page. The number can range between
            1 and 200. The default is 200.

        cursor : typing.Optional[str]
            A pointer to the next page of `EmployeeWage` results to fetch.

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

        Returns
        -------
        SyncPager[EmployeeWage]
            Success

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

        client = Square(
            token="YOUR_TOKEN",
        )
        response = client.labor.employee_wages.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/labor/employee-wages",
            method="GET",
            params={
                "employee_id": employee_id,
                "limit": limit,
                "cursor": cursor,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    ListEmployeeWagesResponse,
                    construct_type(
                        type_=ListEmployeeWagesResponse,  # 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(
                    employee_id=employee_id,
                    limit=limit,
                    cursor=_parsed_next,
                    request_options=request_options,
                )
                _items = _parsed_response.employee_wages
                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, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetEmployeeWageResponse:
        """
        Returns a single `EmployeeWage` specified by `id`.

        Parameters
        ----------
        id : str
            The UUID for the `EmployeeWage` being retrieved.

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

        Returns
        -------
        GetEmployeeWageResponse
            Success

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

        client = Square(
            token="YOUR_TOKEN",
        )
        client.labor.employee_wages.get(
            id="id",
        )
        """
        response = self._raw_client.get(id, request_options=request_options)
        return response.data


class AsyncEmployeeWagesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawEmployeeWagesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawEmployeeWagesClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        employee_id: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[EmployeeWage]:
        """
        Returns a paginated list of `EmployeeWage` instances for a business.

        Parameters
        ----------
        employee_id : typing.Optional[str]
            Filter the returned wages to only those that are associated with the specified employee.

        limit : typing.Optional[int]
            The maximum number of `EmployeeWage` results to return per page. The number can range between
            1 and 200. The default is 200.

        cursor : typing.Optional[str]
            A pointer to the next page of `EmployeeWage` results to fetch.

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

        Returns
        -------
        AsyncPager[EmployeeWage]
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.labor.employee_wages.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/labor/employee-wages",
            method="GET",
            params={
                "employee_id": employee_id,
                "limit": limit,
                "cursor": cursor,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    ListEmployeeWagesResponse,
                    construct_type(
                        type_=ListEmployeeWagesResponse,  # 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(
                    employee_id=employee_id,
                    limit=limit,
                    cursor=_parsed_next,
                    request_options=request_options,
                )
                _items = _parsed_response.employee_wages
                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, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetEmployeeWageResponse:
        """
        Returns a single `EmployeeWage` specified by `id`.

        Parameters
        ----------
        id : str
            The UUID for the `EmployeeWage` being retrieved.

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

        Returns
        -------
        GetEmployeeWageResponse
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.labor.employee_wages.get(
                id="id",
            )


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