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

import typing
from ...core.client_wrapper import SyncClientWrapper
from ...requests.workweek_config import WorkweekConfigParams
from ...core.request_options import RequestOptions
from ...core.http_response import HttpResponse
from ...types.update_workweek_config_response import UpdateWorkweekConfigResponse
from ...core.jsonable_encoder import jsonable_encoder
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 ...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 RawWorkweekConfigsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def get(
        self, id: str, *, workweek_config: WorkweekConfigParams, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[UpdateWorkweekConfigResponse]:
        """
        Updates a `WorkweekConfig`.

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

        workweek_config : WorkweekConfigParams
            The updated `WorkweekConfig` object.

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

        Returns
        -------
        HttpResponse[UpdateWorkweekConfigResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/labor/workweek-configs/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "workweek_config": convert_and_respect_annotation_metadata(
                    object_=workweek_config, annotation=WorkweekConfigParams, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UpdateWorkweekConfigResponse,
                    construct_type(
                        type_=UpdateWorkweekConfigResponse,  # 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 AsyncRawWorkweekConfigsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get(
        self, id: str, *, workweek_config: WorkweekConfigParams, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[UpdateWorkweekConfigResponse]:
        """
        Updates a `WorkweekConfig`.

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

        workweek_config : WorkweekConfigParams
            The updated `WorkweekConfig` object.

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

        Returns
        -------
        AsyncHttpResponse[UpdateWorkweekConfigResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/labor/workweek-configs/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "workweek_config": convert_and_respect_annotation_metadata(
                    object_=workweek_config, annotation=WorkweekConfigParams, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UpdateWorkweekConfigResponse,
                    construct_type(
                        type_=UpdateWorkweekConfigResponse,  # 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)
