# 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 import Employee
from ..types.employee_status import EmployeeStatus
from ..types.get_employee_response import GetEmployeeResponse
from ..types.list_employees_response import ListEmployeesResponse


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

    def list(
        self,
        *,
        location_id: typing.Optional[str] = None,
        status: typing.Optional[EmployeeStatus] = None,
        limit: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Employee, ListEmployeesResponse]:
        """


        Parameters
        ----------
        location_id : typing.Optional[str]


        status : typing.Optional[EmployeeStatus]
            Specifies the EmployeeStatus to filter the employee by.

        limit : typing.Optional[int]
            The number of employees to be returned on each page.

        cursor : typing.Optional[str]
            The token required to retrieve the specified page of results.

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

        Returns
        -------
        SyncPager[Employee, ListEmployeesResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/employees",
            method="GET",
            params={
                "location_id": location_id,
                "status": status,
                "limit": limit,
                "cursor": cursor,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    ListEmployeesResponse,
                    construct_type(
                        type_=ListEmployeesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                _items = _parsed_response.employees
                _parsed_next = _parsed_response.cursor
                _has_next = _parsed_next is not None and _parsed_next != ""
                _get_next = lambda: self.list(
                    location_id=location_id,
                    status=status,
                    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[GetEmployeeResponse]:
        """


        Parameters
        ----------
        id : str
            UUID for the employee that was requested.

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

        Returns
        -------
        HttpResponse[GetEmployeeResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/employees/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetEmployeeResponse,
                    construct_type(
                        type_=GetEmployeeResponse,  # 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 AsyncRawEmployeesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(
        self,
        *,
        location_id: typing.Optional[str] = None,
        status: typing.Optional[EmployeeStatus] = None,
        limit: typing.Optional[int] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Employee, ListEmployeesResponse]:
        """


        Parameters
        ----------
        location_id : typing.Optional[str]


        status : typing.Optional[EmployeeStatus]
            Specifies the EmployeeStatus to filter the employee by.

        limit : typing.Optional[int]
            The number of employees to be returned on each page.

        cursor : typing.Optional[str]
            The token required to retrieve the specified page of results.

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

        Returns
        -------
        AsyncPager[Employee, ListEmployeesResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/employees",
            method="GET",
            params={
                "location_id": location_id,
                "status": status,
                "limit": limit,
                "cursor": cursor,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    ListEmployeesResponse,
                    construct_type(
                        type_=ListEmployeesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                _items = _parsed_response.employees
                _parsed_next = _parsed_response.cursor
                _has_next = _parsed_next is not None and _parsed_next != ""

                async def _get_next():
                    return await self.list(
                        location_id=location_id,
                        status=status,
                        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[GetEmployeeResponse]:
        """


        Parameters
        ----------
        id : str
            UUID for the employee that was requested.

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

        Returns
        -------
        AsyncHttpResponse[GetEmployeeResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/employees/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetEmployeeResponse,
                    construct_type(
                        type_=GetEmployeeResponse,  # 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)
