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

import typing
from ...core.client_wrapper import SyncClientWrapper
from ...core.request_options import RequestOptions
from ...core.http_response import HttpResponse
from ...types.get_wage_setting_response import GetWageSettingResponse
from ...core.jsonable_encoder import jsonable_encoder
from ...core.unchecked_base_model import construct_type
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...requests.wage_setting import WageSettingParams
from ...types.update_wage_setting_response import UpdateWageSettingResponse
from ...core.serialization import convert_and_respect_annotation_metadata
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 RawWageSettingClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def get(
        self, team_member_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[GetWageSettingResponse]:
        """
        Retrieves a `WageSetting` object for a team member specified
        by `TeamMember.id`. For more information, see
        [Troubleshooting the Team API](https://developer.squareup.com/docs/team/troubleshooting#retrievewagesetting).

        Square recommends using [RetrieveTeamMember](api-endpoint:Team-RetrieveTeamMember) or [SearchTeamMembers](api-endpoint:Team-SearchTeamMembers)
        to get this information directly from the `TeamMember.wage_setting` field.

        Parameters
        ----------
        team_member_id : str
            The ID of the team member for which to retrieve the wage setting.

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

        Returns
        -------
        HttpResponse[GetWageSettingResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/team-members/{jsonable_encoder(team_member_id)}/wage-setting",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetWageSettingResponse,
                    construct_type(
                        type_=GetWageSettingResponse,  # 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,
        team_member_id: str,
        *,
        wage_setting: WageSettingParams,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[UpdateWageSettingResponse]:
        """
        Creates or updates a `WageSetting` object. The object is created if a
        `WageSetting` with the specified `team_member_id` doesn't exist. Otherwise,
        it fully replaces the `WageSetting` object for the team member.
        The `WageSetting` is returned on a successful update. For more information, see
        [Troubleshooting the Team API](https://developer.squareup.com/docs/team/troubleshooting#create-or-update-a-wage-setting).

        Square recommends using [CreateTeamMember](api-endpoint:Team-CreateTeamMember) or [UpdateTeamMember](api-endpoint:Team-UpdateTeamMember)
        to manage the `TeamMember.wage_setting` field directly.

        Parameters
        ----------
        team_member_id : str
            The ID of the team member for which to update the `WageSetting` object.

        wage_setting : WageSettingParams
            The complete `WageSetting` object. For all job assignments, specify one of the following:
            - `job_id` (recommended) - If needed, call [ListJobs](api-endpoint:Team-ListJobs) to get a list of all jobs.
            Requires Square API version 2024-12-18 or later.
            - `job_title` - Use the exact, case-sensitive spelling of an existing title unless you want to create a new job.
            This value is ignored if `job_id` is also provided.

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

        Returns
        -------
        HttpResponse[UpdateWageSettingResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/team-members/{jsonable_encoder(team_member_id)}/wage-setting",
            method="PUT",
            json={
                "wage_setting": convert_and_respect_annotation_metadata(
                    object_=wage_setting, annotation=WageSettingParams, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UpdateWageSettingResponse,
                    construct_type(
                        type_=UpdateWageSettingResponse,  # 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 AsyncRawWageSettingClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get(
        self, team_member_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[GetWageSettingResponse]:
        """
        Retrieves a `WageSetting` object for a team member specified
        by `TeamMember.id`. For more information, see
        [Troubleshooting the Team API](https://developer.squareup.com/docs/team/troubleshooting#retrievewagesetting).

        Square recommends using [RetrieveTeamMember](api-endpoint:Team-RetrieveTeamMember) or [SearchTeamMembers](api-endpoint:Team-SearchTeamMembers)
        to get this information directly from the `TeamMember.wage_setting` field.

        Parameters
        ----------
        team_member_id : str
            The ID of the team member for which to retrieve the wage setting.

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

        Returns
        -------
        AsyncHttpResponse[GetWageSettingResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/team-members/{jsonable_encoder(team_member_id)}/wage-setting",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetWageSettingResponse,
                    construct_type(
                        type_=GetWageSettingResponse,  # 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,
        team_member_id: str,
        *,
        wage_setting: WageSettingParams,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[UpdateWageSettingResponse]:
        """
        Creates or updates a `WageSetting` object. The object is created if a
        `WageSetting` with the specified `team_member_id` doesn't exist. Otherwise,
        it fully replaces the `WageSetting` object for the team member.
        The `WageSetting` is returned on a successful update. For more information, see
        [Troubleshooting the Team API](https://developer.squareup.com/docs/team/troubleshooting#create-or-update-a-wage-setting).

        Square recommends using [CreateTeamMember](api-endpoint:Team-CreateTeamMember) or [UpdateTeamMember](api-endpoint:Team-UpdateTeamMember)
        to manage the `TeamMember.wage_setting` field directly.

        Parameters
        ----------
        team_member_id : str
            The ID of the team member for which to update the `WageSetting` object.

        wage_setting : WageSettingParams
            The complete `WageSetting` object. For all job assignments, specify one of the following:
            - `job_id` (recommended) - If needed, call [ListJobs](api-endpoint:Team-ListJobs) to get a list of all jobs.
            Requires Square API version 2024-12-18 or later.
            - `job_title` - Use the exact, case-sensitive spelling of an existing title unless you want to create a new job.
            This value is ignored if `job_id` is also provided.

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

        Returns
        -------
        AsyncHttpResponse[UpdateWageSettingResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/team-members/{jsonable_encoder(team_member_id)}/wage-setting",
            method="PUT",
            json={
                "wage_setting": convert_and_respect_annotation_metadata(
                    object_=wage_setting, annotation=WageSettingParams, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UpdateWageSettingResponse,
                    construct_type(
                        type_=UpdateWageSettingResponse,  # 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)
