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

import typing
from json.decoder import JSONDecodeError

from ...core.api_error import ApiError
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.http_response import AsyncHttpResponse, HttpResponse
from ...core.jsonable_encoder import jsonable_encoder
from ...core.pagination import AsyncPager, SyncPager
from ...core.request_options import RequestOptions
from ...core.unchecked_base_model import construct_type
from ...types.employee_wage import EmployeeWage
from ...types.get_employee_wage_response import GetEmployeeWageResponse
from ...types.list_employee_wages_response import ListEmployeeWagesResponse


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

    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, ListEmployeeWagesResponse]:
        """
        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, ListEmployeeWagesResponse]
            Success
        """
        _response = self._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(),
                    ),
                )
                _items = _parsed_response.employee_wages
                _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,
                )
                return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[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
        -------
        HttpResponse[GetEmployeeWageResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/labor/employee-wages/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetEmployeeWageResponse,
                    construct_type(
                        type_=GetEmployeeWageResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


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

    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, ListEmployeeWagesResponse]:
        """
        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, ListEmployeeWagesResponse]
            Success
        """
        _response = await self._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(),
                    ),
                )
                _items = _parsed_response.employee_wages
                _parsed_next = _parsed_response.cursor
                _has_next = _parsed_next is not None and _parsed_next != ""

                async def _get_next():
                    return await self.list(
                        employee_id=employee_id,
                        limit=limit,
                        cursor=_parsed_next,
                        request_options=request_options,
                    )

                return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[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
        -------
        AsyncHttpResponse[GetEmployeeWageResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/labor/employee-wages/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetEmployeeWageResponse,
                    construct_type(
                        type_=GetEmployeeWageResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
