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

import typing
from ...core.client_wrapper import SyncClientWrapper
from ...requests.break_type import BreakTypeParams
from ...core.request_options import RequestOptions
from ...core.http_response import HttpResponse
from ...types.create_break_type_response import CreateBreakTypeResponse
from ...core.serialization import convert_and_respect_annotation_metadata
from ...core.unchecked_base_model import construct_type
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...types.get_break_type_response import GetBreakTypeResponse
from ...core.jsonable_encoder import jsonable_encoder
from ...types.update_break_type_response import UpdateBreakTypeResponse
from ...types.delete_break_type_response import DeleteBreakTypeResponse
from ...core.client_wrapper import AsyncClientWrapper
from ...core.http_response import AsyncHttpResponse

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


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

    def create(
        self,
        *,
        break_type: BreakTypeParams,
        idempotency_key: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[CreateBreakTypeResponse]:
        """
        Creates a new `BreakType`.

        A `BreakType` is a template for creating `Break` objects.
        You must provide the following values in your request to this
        endpoint:

        - `location_id`
        - `break_name`
        - `expected_duration`
        - `is_paid`

        You can only have three `BreakType` instances per location. If you attempt to add a fourth
        `BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of 3 breaks per location."
        is returned.

        Parameters
        ----------
        break_type : BreakTypeParams
            The `BreakType` to be created.

        idempotency_key : typing.Optional[str]
            A unique string value to ensure the idempotency of the operation.

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

        Returns
        -------
        HttpResponse[CreateBreakTypeResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/labor/break-types",
            method="POST",
            json={
                "idempotency_key": idempotency_key,
                "break_type": convert_and_respect_annotation_metadata(
                    object_=break_type, annotation=BreakTypeParams, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CreateBreakTypeResponse,
                    construct_type(
                        type_=CreateBreakTypeResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _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
    ) -> HttpResponse[GetBreakTypeResponse]:
        """
        Returns a single `BreakType` specified by `id`.

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

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

        Returns
        -------
        HttpResponse[GetBreakTypeResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/labor/break-types/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetBreakTypeResponse,
                    construct_type(
                        type_=GetBreakTypeResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _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 update(
        self, id: str, *, break_type: BreakTypeParams, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[UpdateBreakTypeResponse]:
        """
        Updates an existing `BreakType`.

        Parameters
        ----------
        id : str
             The UUID for the `BreakType` being updated.

        break_type : BreakTypeParams
            The updated `BreakType`.

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

        Returns
        -------
        HttpResponse[UpdateBreakTypeResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/labor/break-types/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "break_type": convert_and_respect_annotation_metadata(
                    object_=break_type, annotation=BreakTypeParams, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UpdateBreakTypeResponse,
                    construct_type(
                        type_=UpdateBreakTypeResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _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 delete(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[DeleteBreakTypeResponse]:
        """
        Deletes an existing `BreakType`.

        A `BreakType` can be deleted even if it is referenced from a `Shift`.

        Parameters
        ----------
        id : str
            The UUID for the `BreakType` being deleted.

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

        Returns
        -------
        HttpResponse[DeleteBreakTypeResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/labor/break-types/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeleteBreakTypeResponse,
                    construct_type(
                        type_=DeleteBreakTypeResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _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)


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

    async def create(
        self,
        *,
        break_type: BreakTypeParams,
        idempotency_key: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[CreateBreakTypeResponse]:
        """
        Creates a new `BreakType`.

        A `BreakType` is a template for creating `Break` objects.
        You must provide the following values in your request to this
        endpoint:

        - `location_id`
        - `break_name`
        - `expected_duration`
        - `is_paid`

        You can only have three `BreakType` instances per location. If you attempt to add a fourth
        `BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of 3 breaks per location."
        is returned.

        Parameters
        ----------
        break_type : BreakTypeParams
            The `BreakType` to be created.

        idempotency_key : typing.Optional[str]
            A unique string value to ensure the idempotency of the operation.

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

        Returns
        -------
        AsyncHttpResponse[CreateBreakTypeResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/labor/break-types",
            method="POST",
            json={
                "idempotency_key": idempotency_key,
                "break_type": convert_and_respect_annotation_metadata(
                    object_=break_type, annotation=BreakTypeParams, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    CreateBreakTypeResponse,
                    construct_type(
                        type_=CreateBreakTypeResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _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
    ) -> AsyncHttpResponse[GetBreakTypeResponse]:
        """
        Returns a single `BreakType` specified by `id`.

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

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

        Returns
        -------
        AsyncHttpResponse[GetBreakTypeResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/labor/break-types/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetBreakTypeResponse,
                    construct_type(
                        type_=GetBreakTypeResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _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 update(
        self, id: str, *, break_type: BreakTypeParams, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[UpdateBreakTypeResponse]:
        """
        Updates an existing `BreakType`.

        Parameters
        ----------
        id : str
             The UUID for the `BreakType` being updated.

        break_type : BreakTypeParams
            The updated `BreakType`.

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

        Returns
        -------
        AsyncHttpResponse[UpdateBreakTypeResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/labor/break-types/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "break_type": convert_and_respect_annotation_metadata(
                    object_=break_type, annotation=BreakTypeParams, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UpdateBreakTypeResponse,
                    construct_type(
                        type_=UpdateBreakTypeResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _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 delete(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[DeleteBreakTypeResponse]:
        """
        Deletes an existing `BreakType`.

        A `BreakType` can be deleted even if it is referenced from a `Shift`.

        Parameters
        ----------
        id : str
            The UUID for the `BreakType` being deleted.

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

        Returns
        -------
        AsyncHttpResponse[DeleteBreakTypeResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/labor/break-types/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeleteBreakTypeResponse,
                    construct_type(
                        type_=DeleteBreakTypeResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _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)
