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

import datetime as dt
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.request_options import RequestOptions
from ..core.unchecked_base_model import construct_type
from ..types.hotkeys import Hotkeys
from ..types.lse_user import LseUser
from ..types.lse_user_api import LseUserApi
from ..types.who_am_i_user import WhoAmIUser
from .types.get_token_users_response import GetTokenUsersResponse
from .types.reset_token_users_response import ResetTokenUsersResponse

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


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

    def get_current_user(self, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[LseUserApi]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Get info about the currently authenticated user.

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

        Returns
        -------
        HttpResponse[LseUserApi]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/current-user",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUserApi,
                    construct_type(
                        type_=LseUserApi,  # 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)

    def update_current_user(
        self,
        *,
        active_organization: typing.Optional[int] = OMIT,
        allow_newsletters: typing.Optional[bool] = OMIT,
        custom_hotkeys: typing.Optional[typing.Any] = OMIT,
        date_joined: typing.Optional[dt.datetime] = OMIT,
        email_notification_settings: typing.Optional[typing.Any] = OMIT,
        first_name: typing.Optional[str] = OMIT,
        is_email_verified: typing.Optional[bool] = OMIT,
        last_name: typing.Optional[str] = OMIT,
        onboarding_state: typing.Optional[str] = OMIT,
        password: typing.Optional[str] = OMIT,
        phone: typing.Optional[str] = OMIT,
        username: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[LseUserApi]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update details for the currently authenticated user.

        Parameters
        ----------
        active_organization : typing.Optional[int]

        allow_newsletters : typing.Optional[bool]
            Allow sending newsletters to user

        custom_hotkeys : typing.Optional[typing.Any]
            Custom keyboard shortcuts configuration for the user interface

        date_joined : typing.Optional[dt.datetime]

        email_notification_settings : typing.Optional[typing.Any]

        first_name : typing.Optional[str]

        is_email_verified : typing.Optional[bool]

        last_name : typing.Optional[str]

        onboarding_state : typing.Optional[str]

        password : typing.Optional[str]

        phone : typing.Optional[str]

        username : typing.Optional[str]

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

        Returns
        -------
        HttpResponse[LseUserApi]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/current-user",
            method="PATCH",
            json={
                "active_organization": active_organization,
                "allow_newsletters": allow_newsletters,
                "custom_hotkeys": custom_hotkeys,
                "date_joined": date_joined,
                "email_notification_settings": email_notification_settings,
                "first_name": first_name,
                "is_email_verified": is_email_verified,
                "last_name": last_name,
                "onboarding_state": onboarding_state,
                "password": password,
                "phone": phone,
                "username": username,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUserApi,
                    construct_type(
                        type_=LseUserApi,  # 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)

    def get_hotkeys(self, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[Hotkeys]:
        """
        Retrieve the custom hotkeys configuration for the current user.

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

        Returns
        -------
        HttpResponse[Hotkeys]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/current-user/hotkeys/",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Hotkeys,
                    construct_type(
                        type_=Hotkeys,  # 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)

    def update_hotkeys(
        self,
        *,
        custom_hotkeys: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[Hotkeys]:
        """
        Update the custom hotkeys configuration for the current user.

        Parameters
        ----------
        custom_hotkeys : typing.Optional[typing.Dict[str, typing.Any]]

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

        Returns
        -------
        HttpResponse[Hotkeys]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/current-user/hotkeys/",
            method="PATCH",
            json={
                "custom_hotkeys": custom_hotkeys,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Hotkeys,
                    construct_type(
                        type_=Hotkeys,  # 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)

    def reset_token(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[ResetTokenUsersResponse]:
        """
        Reset the user token for the current user.

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

        Returns
        -------
        HttpResponse[ResetTokenUsersResponse]
            User token response
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/current-user/reset-token/",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResetTokenUsersResponse,
                    construct_type(
                        type_=ResetTokenUsersResponse,  # 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)

    def get_token(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[GetTokenUsersResponse]:
        """
        Get a user token to authenticate to the API as the current user.

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

        Returns
        -------
        HttpResponse[GetTokenUsersResponse]
            User token response
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/current-user/token",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetTokenUsersResponse,
                    construct_type(
                        type_=GetTokenUsersResponse,  # 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)

    def whoami(self, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[WhoAmIUser]:
        """
        Retrieve details of the account that you are using to access the API.

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

        Returns
        -------
        HttpResponse[WhoAmIUser]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/current-user/whoami",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WhoAmIUser,
                    construct_type(
                        type_=WhoAmIUser,  # 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)

    def list(
        self, *, ordering: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[typing.List[LseUserApi]]:
        """
        List the users that exist on the Label Studio server.

        Parameters
        ----------
        ordering : typing.Optional[str]
            Which field to use when ordering the results.

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

        Returns
        -------
        HttpResponse[typing.List[LseUserApi]]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/users/",
            method="GET",
            params={
                "ordering": ordering,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[LseUserApi],
                    construct_type(
                        type_=typing.List[LseUserApi],  # 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)

    def create(
        self,
        *,
        allow_newsletters: typing.Optional[bool] = OMIT,
        avatar: typing.Optional[str] = OMIT,
        email: typing.Optional[str] = OMIT,
        first_name: typing.Optional[str] = OMIT,
        id: typing.Optional[int] = OMIT,
        initials: typing.Optional[str] = OMIT,
        last_name: typing.Optional[str] = OMIT,
        phone: typing.Optional[str] = OMIT,
        username: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[LseUser]:
        """
        Create a user in Label Studio.

        Parameters
        ----------
        allow_newsletters : typing.Optional[bool]
            Whether the user allows newsletters

        avatar : typing.Optional[str]
            Avatar URL of the user

        email : typing.Optional[str]
            Email of the user

        first_name : typing.Optional[str]
            First name of the user

        id : typing.Optional[int]
            User ID

        initials : typing.Optional[str]
            Initials of the user

        last_name : typing.Optional[str]
            Last name of the user

        phone : typing.Optional[str]
            Phone number of the user

        username : typing.Optional[str]
            Username of the user

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

        Returns
        -------
        HttpResponse[LseUser]

        """
        _response = self._client_wrapper.httpx_client.request(
            "api/users/",
            method="POST",
            json={
                "allow_newsletters": allow_newsletters,
                "avatar": avatar,
                "email": email,
                "first_name": first_name,
                "id": id,
                "initials": initials,
                "last_name": last_name,
                "phone": phone,
                "username": username,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUser,
                    construct_type(
                        type_=LseUser,  # 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)

    def get(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[LseUser]:
        """
        Get info about a specific Label Studio user, based on the user ID.

        Parameters
        ----------
        id : int
            User ID

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

        Returns
        -------
        HttpResponse[LseUser]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/users/{jsonable_encoder(id)}/",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUser,
                    construct_type(
                        type_=LseUser,  # 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)

    def delete(self, id: int, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
        """
        Delete a specific Label Studio user. Only available in community edition.

        <Warning>Use caution when deleting a user, as this can cause issues such as breaking the "Annotated by" filter or leaving orphaned records.</Warning>

        Parameters
        ----------
        id : int
            User ID

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/users/{jsonable_encoder(id)}/",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            _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 update(
        self,
        id: int,
        *,
        allow_newsletters: typing.Optional[bool] = OMIT,
        avatar: typing.Optional[str] = OMIT,
        email: typing.Optional[str] = OMIT,
        first_name: typing.Optional[str] = OMIT,
        update_users_request_id: typing.Optional[int] = OMIT,
        initials: typing.Optional[str] = OMIT,
        last_name: typing.Optional[str] = OMIT,
        phone: typing.Optional[str] = OMIT,
        username: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[LseUser]:
        """

                Update details for a specific user, such as their name or contact information, in Label Studio.


        Parameters
        ----------
        id : int
            User ID

        allow_newsletters : typing.Optional[bool]
            Whether the user allows newsletters

        avatar : typing.Optional[str]
            Avatar URL of the user

        email : typing.Optional[str]
            Email of the user

        first_name : typing.Optional[str]
            First name of the user

        update_users_request_id : typing.Optional[int]
            User ID

        initials : typing.Optional[str]
            Initials of the user

        last_name : typing.Optional[str]
            Last name of the user

        phone : typing.Optional[str]
            Phone number of the user

        username : typing.Optional[str]
            Username of the user

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

        Returns
        -------
        HttpResponse[LseUser]

        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/users/{jsonable_encoder(id)}/",
            method="PATCH",
            json={
                "allow_newsletters": allow_newsletters,
                "avatar": avatar,
                "email": email,
                "first_name": first_name,
                "id": update_users_request_id,
                "initials": initials,
                "last_name": last_name,
                "phone": phone,
                "username": username,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUser,
                    construct_type(
                        type_=LseUser,  # 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 AsyncRawUsersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get_current_user(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[LseUserApi]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Get info about the currently authenticated user.

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

        Returns
        -------
        AsyncHttpResponse[LseUserApi]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/current-user",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUserApi,
                    construct_type(
                        type_=LseUserApi,  # 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)

    async def update_current_user(
        self,
        *,
        active_organization: typing.Optional[int] = OMIT,
        allow_newsletters: typing.Optional[bool] = OMIT,
        custom_hotkeys: typing.Optional[typing.Any] = OMIT,
        date_joined: typing.Optional[dt.datetime] = OMIT,
        email_notification_settings: typing.Optional[typing.Any] = OMIT,
        first_name: typing.Optional[str] = OMIT,
        is_email_verified: typing.Optional[bool] = OMIT,
        last_name: typing.Optional[str] = OMIT,
        onboarding_state: typing.Optional[str] = OMIT,
        password: typing.Optional[str] = OMIT,
        phone: typing.Optional[str] = OMIT,
        username: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[LseUserApi]:
        """
        <Card href="https://humansignal.com/goenterprise">
                <img style="pointer-events: none; margin-left: 0px; margin-right: 0px;" src="https://docs.humansignal.com/images/badge.svg" alt="Label Studio Enterprise badge"/>
                <p style="margin-top: 10px; font-size: 14px;">
                    This endpoint is not available in Label Studio Community Edition. [Learn more about Label Studio Enterprise](https://humansignal.com/goenterprise)
                </p>
            </Card>
        Update details for the currently authenticated user.

        Parameters
        ----------
        active_organization : typing.Optional[int]

        allow_newsletters : typing.Optional[bool]
            Allow sending newsletters to user

        custom_hotkeys : typing.Optional[typing.Any]
            Custom keyboard shortcuts configuration for the user interface

        date_joined : typing.Optional[dt.datetime]

        email_notification_settings : typing.Optional[typing.Any]

        first_name : typing.Optional[str]

        is_email_verified : typing.Optional[bool]

        last_name : typing.Optional[str]

        onboarding_state : typing.Optional[str]

        password : typing.Optional[str]

        phone : typing.Optional[str]

        username : typing.Optional[str]

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

        Returns
        -------
        AsyncHttpResponse[LseUserApi]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/current-user",
            method="PATCH",
            json={
                "active_organization": active_organization,
                "allow_newsletters": allow_newsletters,
                "custom_hotkeys": custom_hotkeys,
                "date_joined": date_joined,
                "email_notification_settings": email_notification_settings,
                "first_name": first_name,
                "is_email_verified": is_email_verified,
                "last_name": last_name,
                "onboarding_state": onboarding_state,
                "password": password,
                "phone": phone,
                "username": username,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUserApi,
                    construct_type(
                        type_=LseUserApi,  # 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)

    async def get_hotkeys(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[Hotkeys]:
        """
        Retrieve the custom hotkeys configuration for the current user.

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

        Returns
        -------
        AsyncHttpResponse[Hotkeys]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/current-user/hotkeys/",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Hotkeys,
                    construct_type(
                        type_=Hotkeys,  # 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)

    async def update_hotkeys(
        self,
        *,
        custom_hotkeys: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[Hotkeys]:
        """
        Update the custom hotkeys configuration for the current user.

        Parameters
        ----------
        custom_hotkeys : typing.Optional[typing.Dict[str, typing.Any]]

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

        Returns
        -------
        AsyncHttpResponse[Hotkeys]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/current-user/hotkeys/",
            method="PATCH",
            json={
                "custom_hotkeys": custom_hotkeys,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Hotkeys,
                    construct_type(
                        type_=Hotkeys,  # 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)

    async def reset_token(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[ResetTokenUsersResponse]:
        """
        Reset the user token for the current user.

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

        Returns
        -------
        AsyncHttpResponse[ResetTokenUsersResponse]
            User token response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/current-user/reset-token/",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResetTokenUsersResponse,
                    construct_type(
                        type_=ResetTokenUsersResponse,  # 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)

    async def get_token(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[GetTokenUsersResponse]:
        """
        Get a user token to authenticate to the API as the current user.

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

        Returns
        -------
        AsyncHttpResponse[GetTokenUsersResponse]
            User token response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/current-user/token",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetTokenUsersResponse,
                    construct_type(
                        type_=GetTokenUsersResponse,  # 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)

    async def whoami(self, *, request_options: typing.Optional[RequestOptions] = None) -> AsyncHttpResponse[WhoAmIUser]:
        """
        Retrieve details of the account that you are using to access the API.

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

        Returns
        -------
        AsyncHttpResponse[WhoAmIUser]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/current-user/whoami",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    WhoAmIUser,
                    construct_type(
                        type_=WhoAmIUser,  # 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)

    async def list(
        self, *, ordering: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[typing.List[LseUserApi]]:
        """
        List the users that exist on the Label Studio server.

        Parameters
        ----------
        ordering : typing.Optional[str]
            Which field to use when ordering the results.

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

        Returns
        -------
        AsyncHttpResponse[typing.List[LseUserApi]]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/users/",
            method="GET",
            params={
                "ordering": ordering,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[LseUserApi],
                    construct_type(
                        type_=typing.List[LseUserApi],  # 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)

    async def create(
        self,
        *,
        allow_newsletters: typing.Optional[bool] = OMIT,
        avatar: typing.Optional[str] = OMIT,
        email: typing.Optional[str] = OMIT,
        first_name: typing.Optional[str] = OMIT,
        id: typing.Optional[int] = OMIT,
        initials: typing.Optional[str] = OMIT,
        last_name: typing.Optional[str] = OMIT,
        phone: typing.Optional[str] = OMIT,
        username: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[LseUser]:
        """
        Create a user in Label Studio.

        Parameters
        ----------
        allow_newsletters : typing.Optional[bool]
            Whether the user allows newsletters

        avatar : typing.Optional[str]
            Avatar URL of the user

        email : typing.Optional[str]
            Email of the user

        first_name : typing.Optional[str]
            First name of the user

        id : typing.Optional[int]
            User ID

        initials : typing.Optional[str]
            Initials of the user

        last_name : typing.Optional[str]
            Last name of the user

        phone : typing.Optional[str]
            Phone number of the user

        username : typing.Optional[str]
            Username of the user

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

        Returns
        -------
        AsyncHttpResponse[LseUser]

        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/users/",
            method="POST",
            json={
                "allow_newsletters": allow_newsletters,
                "avatar": avatar,
                "email": email,
                "first_name": first_name,
                "id": id,
                "initials": initials,
                "last_name": last_name,
                "phone": phone,
                "username": username,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUser,
                    construct_type(
                        type_=LseUser,  # 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)

    async def get(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[LseUser]:
        """
        Get info about a specific Label Studio user, based on the user ID.

        Parameters
        ----------
        id : int
            User ID

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

        Returns
        -------
        AsyncHttpResponse[LseUser]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/users/{jsonable_encoder(id)}/",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUser,
                    construct_type(
                        type_=LseUser,  # 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)

    async def delete(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Delete a specific Label Studio user. Only available in community edition.

        <Warning>Use caution when deleting a user, as this can cause issues such as breaking the "Annotated by" filter or leaving orphaned records.</Warning>

        Parameters
        ----------
        id : int
            User ID

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/users/{jsonable_encoder(id)}/",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            _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 update(
        self,
        id: int,
        *,
        allow_newsletters: typing.Optional[bool] = OMIT,
        avatar: typing.Optional[str] = OMIT,
        email: typing.Optional[str] = OMIT,
        first_name: typing.Optional[str] = OMIT,
        update_users_request_id: typing.Optional[int] = OMIT,
        initials: typing.Optional[str] = OMIT,
        last_name: typing.Optional[str] = OMIT,
        phone: typing.Optional[str] = OMIT,
        username: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[LseUser]:
        """

                Update details for a specific user, such as their name or contact information, in Label Studio.


        Parameters
        ----------
        id : int
            User ID

        allow_newsletters : typing.Optional[bool]
            Whether the user allows newsletters

        avatar : typing.Optional[str]
            Avatar URL of the user

        email : typing.Optional[str]
            Email of the user

        first_name : typing.Optional[str]
            First name of the user

        update_users_request_id : typing.Optional[int]
            User ID

        initials : typing.Optional[str]
            Initials of the user

        last_name : typing.Optional[str]
            Last name of the user

        phone : typing.Optional[str]
            Phone number of the user

        username : typing.Optional[str]
            Username of the user

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

        Returns
        -------
        AsyncHttpResponse[LseUser]

        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/users/{jsonable_encoder(id)}/",
            method="PATCH",
            json={
                "allow_newsletters": allow_newsletters,
                "avatar": avatar,
                "email": email,
                "first_name": first_name,
                "id": update_users_request_id,
                "initials": initials,
                "last_name": last_name,
                "phone": phone,
                "username": username,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    LseUser,
                    construct_type(
                        type_=LseUser,  # 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)
