# 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 ..types.paginated_users_response import PaginatedUsersResponse
from ..core.pydantic_utilities import parse_obj_as
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.http_validation_error import HttpValidationError
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..types.client_facing_user_key import ClientFacingUserKey
from ..errors.bad_request_error import BadRequestError
from ..types.metrics_result import MetricsResult
from ..types.user_sign_in_token_response import UserSignInTokenResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..types.client_facing_provider_with_status import ClientFacingProviderWithStatus
from ..types.client_facing_user import ClientFacingUser
from ..types.user_success_response import UserSuccessResponse
from ..types.user_info import UserInfo
from ..types.responsible_relationship import ResponsibleRelationship
from ..types.vital_core_schemas_db_schemas_lab_test_insurance_person_details import (
    VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails,
)
from ..types.guarantor_details import GuarantorDetails
from ..types.client_facing_insurance import ClientFacingInsurance
from ..types.address import Address
from ..types.providers import Providers
from ..types.user_refresh_success_response import UserRefreshSuccessResponse
from ..core.client_wrapper import AsyncClientWrapper

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


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

    def get_all(
        self,
        *,
        offset: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PaginatedUsersResponse:
        """
        GET All users for team.

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

        limit : typing.Optional[int]

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

        Returns
        -------
        PaginatedUsersResponse
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.get_all()
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/user",
            method="GET",
            params={
                "offset": offset,
                "limit": limit,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    PaginatedUsersResponse,
                    parse_obj_as(
                        type_=PaginatedUsersResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 create(
        self,
        *,
        client_user_id: str,
        fallback_time_zone: typing.Optional[str] = OMIT,
        fallback_birth_date: typing.Optional[str] = OMIT,
        ingestion_start: typing.Optional[str] = OMIT,
        ingestion_end: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClientFacingUserKey:
        """
        POST Create a Vital user given a client_user_id and returns the user_id.

        Parameters
        ----------
        client_user_id : str
            A unique ID representing the end user. Typically this will be a user ID from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.

        fallback_time_zone : typing.Optional[str]

                Fallback time zone of the user, in the form of a valid IANA tzdatabase identifier (e.g., `Europe/London` or `America/Los_Angeles`).
                Used when pulling data from sources that are completely time zone agnostic (e.g., all time is relative to UTC clock, without any time zone attributions on data points).


        fallback_birth_date : typing.Optional[str]
            Fallback date of birth of the user, in YYYY-mm-dd format. Used for calculating max heartrate for providers that don not provide users' age.

        ingestion_start : typing.Optional[str]
            Starting bound for user data ingestion. Data older than this date will not be ingested.

        ingestion_end : typing.Optional[str]
            Ending bound for user data ingestion. Data from this date or later will not be ingested and the connection will be deregistered.

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

        Returns
        -------
        ClientFacingUserKey
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.create(
            client_user_id="client_user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/user",
            method="POST",
            json={
                "client_user_id": client_user_id,
                "fallback_time_zone": fallback_time_zone,
                "fallback_birth_date": fallback_birth_date,
                "ingestion_start": ingestion_start,
                "ingestion_end": ingestion_end,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingUserKey,
                    parse_obj_as(
                        type_=ClientFacingUserKey,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_team_metrics(self, *, request_options: typing.Optional[RequestOptions] = None) -> MetricsResult:
        """
        GET metrics for team.

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

        Returns
        -------
        MetricsResult
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.get_team_metrics()
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/user/metrics",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    MetricsResult,
                    parse_obj_as(
                        type_=MetricsResult,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _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_user_sign_in_token(
        self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UserSignInTokenResponse:
        """
        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        UserSignInTokenResponse
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.get_user_sign_in_token(
            user_id="user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/sign_in_token",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserSignInTokenResponse,
                    parse_obj_as(
                        type_=UserSignInTokenResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_connected_providers(
        self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.List[ClientFacingProviderWithStatus]]:
        """
        GET Users connected providers

        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        typing.Dict[str, typing.List[ClientFacingProviderWithStatus]]
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.get_connected_providers(
            user_id="user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/providers/{jsonable_encoder(user_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.Dict[str, typing.List[ClientFacingProviderWithStatus]],
                    parse_obj_as(
                        type_=typing.Dict[str, typing.List[ClientFacingProviderWithStatus]],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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, user_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ClientFacingUser:
        """
        GET User details given the user_id.

        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        ClientFacingUser
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.get(
            user_id="user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingUser,
                    parse_obj_as(
                        type_=ClientFacingUser,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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, user_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> UserSuccessResponse:
        """
        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        UserSuccessResponse
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.delete(
            user_id="user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserSuccessResponse,
                    parse_obj_as(
                        type_=UserSuccessResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 patch(
        self,
        user_id: str,
        *,
        fallback_time_zone: typing.Optional[str] = OMIT,
        fallback_birth_date: typing.Optional[str] = OMIT,
        ingestion_start: typing.Optional[str] = OMIT,
        ingestion_end: typing.Optional[str] = OMIT,
        client_user_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Parameters
        ----------
        user_id : str

        fallback_time_zone : typing.Optional[str]

                Fallback time zone of the user, in the form of a valid IANA tzdatabase identifier (e.g., `Europe/London` or `America/Los_Angeles`).
                Used when pulling data from sources that are completely time zone agnostic (e.g., all time is relative to UTC clock, without any time zone attributions on data points).


        fallback_birth_date : typing.Optional[str]
            Fallback date of birth of the user, in YYYY-mm-dd format. Used for calculating max heartrate for providers that don not provide users' age.

        ingestion_start : typing.Optional[str]
            Starting bound for user data ingestion. Data older than this date will not be ingested.

        ingestion_end : typing.Optional[str]
            Ending bound for user data ingestion. Data from this date or later will not be ingested and the connection will be deregistered.

        client_user_id : typing.Optional[str]
            A unique ID representing the end user. Typically this will be a user ID from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.

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

        Returns
        -------
        None

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.patch(
            user_id="user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}",
            method="PATCH",
            json={
                "fallback_time_zone": fallback_time_zone,
                "fallback_birth_date": fallback_birth_date,
                "ingestion_start": ingestion_start,
                "ingestion_end": ingestion_end,
                "client_user_id": client_user_id,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_latest_user_info(
        self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UserInfo:
        """
        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        UserInfo
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.get_latest_user_info(
            user_id="user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/info/latest",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserInfo,
                    parse_obj_as(
                        type_=UserInfo,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 create_insurance(
        self,
        user_id: str,
        *,
        payor_code: str,
        member_id: str,
        relationship: ResponsibleRelationship,
        insured: VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails,
        group_id: typing.Optional[str] = OMIT,
        guarantor: typing.Optional[GuarantorDetails] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClientFacingInsurance:
        """
        Parameters
        ----------
        user_id : str

        payor_code : str

        member_id : str

        relationship : ResponsibleRelationship

        insured : VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails

        group_id : typing.Optional[str]

        guarantor : typing.Optional[GuarantorDetails]

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

        Returns
        -------
        ClientFacingInsurance
            Successful Response

        Examples
        --------
        from vital import (
            Address,
            Gender,
            ResponsibleRelationship,
            Vital,
            VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails,
        )

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.create_insurance(
            user_id="user_id",
            payor_code="payor_code",
            member_id="member_id",
            relationship=ResponsibleRelationship.SELF,
            insured=VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails(
                first_name="first_name",
                last_name="last_name",
                gender=Gender.FEMALE,
                address=Address(
                    first_line="first_line",
                    country="country",
                    zip="zip",
                    city="city",
                    state="state",
                ),
                dob="dob",
                email="email",
                phone_number="phone_number",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/insurance",
            method="POST",
            json={
                "payor_code": payor_code,
                "member_id": member_id,
                "group_id": group_id,
                "relationship": relationship,
                "insured": insured,
                "guarantor": guarantor,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingInsurance,
                    parse_obj_as(
                        type_=ClientFacingInsurance,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_latest_insurance(
        self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ClientFacingInsurance:
        """
        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        ClientFacingInsurance
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.get_latest_insurance(
            user_id="user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/insurance/latest",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingInsurance,
                    parse_obj_as(
                        type_=ClientFacingInsurance,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 upsert_user_info(
        self,
        user_id: str,
        *,
        first_name: str,
        last_name: str,
        email: str,
        phone_number: str,
        gender: str,
        dob: str,
        address: Address,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserInfo:
        """
        Parameters
        ----------
        user_id : str

        first_name : str

        last_name : str

        email : str

        phone_number : str

        gender : str

        dob : str

        address : Address

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

        Returns
        -------
        UserInfo
            Successful Response

        Examples
        --------
        from vital import Address, Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.upsert_user_info(
            user_id="user_id",
            first_name="first_name",
            last_name="last_name",
            email="email",
            phone_number="phone_number",
            gender="gender",
            dob="dob",
            address=Address(
                first_line="first_line",
                country="country",
                zip="zip",
                city="city",
                state="state",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/info",
            method="PATCH",
            json={
                "first_name": first_name,
                "last_name": last_name,
                "email": email,
                "phone_number": phone_number,
                "gender": gender,
                "dob": dob,
                "address": address,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserInfo,
                    parse_obj_as(
                        type_=UserInfo,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_by_client_user_id(
        self, client_user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ClientFacingUser:
        """
        GET user_id from client_user_id.

        Parameters
        ----------
        client_user_id : str
            A unique ID representing the end user. Typically this will be a user ID number from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.

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

        Returns
        -------
        ClientFacingUser
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.get_by_client_user_id(
            client_user_id="client_user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/resolve/{jsonable_encoder(client_user_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingUser,
                    parse_obj_as(
                        type_=ClientFacingUser,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 deregister_provider(
        self, user_id: str, provider: Providers, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UserSuccessResponse:
        """
        Parameters
        ----------
        user_id : str

        provider : Providers
            Provider slug. e.g., `oura`, `fitbit`, `garmin`.

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

        Returns
        -------
        UserSuccessResponse
            Successful Response

        Examples
        --------
        from vital import Providers, Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.deregister_provider(
            user_id="user_id",
            provider=Providers.OURA,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/{jsonable_encoder(provider)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserSuccessResponse,
                    parse_obj_as(
                        type_=UserSuccessResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 undo_delete(
        self,
        *,
        user_id: typing.Optional[str] = None,
        client_user_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserSuccessResponse:
        """
        Parameters
        ----------
        user_id : typing.Optional[str]
            User ID to undo deletion. Mutually exclusive with `client_user_id`.

        client_user_id : typing.Optional[str]
            Client User ID to undo deletion. Mutually exclusive with `user_id`.

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

        Returns
        -------
        UserSuccessResponse
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.undo_delete()
        """
        _response = self._client_wrapper.httpx_client.request(
            "v2/user/undo_delete",
            method="POST",
            params={
                "user_id": user_id,
                "client_user_id": client_user_id,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserSuccessResponse,
                    parse_obj_as(
                        type_=UserSuccessResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 refresh(
        self,
        user_id: str,
        *,
        timeout: typing.Optional[float] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserRefreshSuccessResponse:
        """
        Trigger a manual refresh for a specific user

        Parameters
        ----------
        user_id : str

        timeout : typing.Optional[float]

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

        Returns
        -------
        UserRefreshSuccessResponse
            Successful Response

        Examples
        --------
        from vital import Vital

        client = Vital(
            api_key="YOUR_API_KEY",
        )
        client.user.refresh(
            user_id="user_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/user/refresh/{jsonable_encoder(user_id)}",
            method="POST",
            params={
                "timeout": timeout,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserRefreshSuccessResponse,
                    parse_obj_as(
                        type_=UserRefreshSuccessResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 AsyncUserClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get_all(
        self,
        *,
        offset: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PaginatedUsersResponse:
        """
        GET All users for team.

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

        limit : typing.Optional[int]

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

        Returns
        -------
        PaginatedUsersResponse
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.get_all()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/user",
            method="GET",
            params={
                "offset": offset,
                "limit": limit,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    PaginatedUsersResponse,
                    parse_obj_as(
                        type_=PaginatedUsersResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 create(
        self,
        *,
        client_user_id: str,
        fallback_time_zone: typing.Optional[str] = OMIT,
        fallback_birth_date: typing.Optional[str] = OMIT,
        ingestion_start: typing.Optional[str] = OMIT,
        ingestion_end: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClientFacingUserKey:
        """
        POST Create a Vital user given a client_user_id and returns the user_id.

        Parameters
        ----------
        client_user_id : str
            A unique ID representing the end user. Typically this will be a user ID from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.

        fallback_time_zone : typing.Optional[str]

                Fallback time zone of the user, in the form of a valid IANA tzdatabase identifier (e.g., `Europe/London` or `America/Los_Angeles`).
                Used when pulling data from sources that are completely time zone agnostic (e.g., all time is relative to UTC clock, without any time zone attributions on data points).


        fallback_birth_date : typing.Optional[str]
            Fallback date of birth of the user, in YYYY-mm-dd format. Used for calculating max heartrate for providers that don not provide users' age.

        ingestion_start : typing.Optional[str]
            Starting bound for user data ingestion. Data older than this date will not be ingested.

        ingestion_end : typing.Optional[str]
            Ending bound for user data ingestion. Data from this date or later will not be ingested and the connection will be deregistered.

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

        Returns
        -------
        ClientFacingUserKey
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.create(
                client_user_id="client_user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/user",
            method="POST",
            json={
                "client_user_id": client_user_id,
                "fallback_time_zone": fallback_time_zone,
                "fallback_birth_date": fallback_birth_date,
                "ingestion_start": ingestion_start,
                "ingestion_end": ingestion_end,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingUserKey,
                    parse_obj_as(
                        type_=ClientFacingUserKey,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_team_metrics(self, *, request_options: typing.Optional[RequestOptions] = None) -> MetricsResult:
        """
        GET metrics for team.

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

        Returns
        -------
        MetricsResult
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.get_team_metrics()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/user/metrics",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    MetricsResult,
                    parse_obj_as(
                        type_=MetricsResult,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            _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_user_sign_in_token(
        self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UserSignInTokenResponse:
        """
        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        UserSignInTokenResponse
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.get_user_sign_in_token(
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/sign_in_token",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserSignInTokenResponse,
                    parse_obj_as(
                        type_=UserSignInTokenResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_connected_providers(
        self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.List[ClientFacingProviderWithStatus]]:
        """
        GET Users connected providers

        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        typing.Dict[str, typing.List[ClientFacingProviderWithStatus]]
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.get_connected_providers(
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/providers/{jsonable_encoder(user_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.Dict[str, typing.List[ClientFacingProviderWithStatus]],
                    parse_obj_as(
                        type_=typing.Dict[str, typing.List[ClientFacingProviderWithStatus]],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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, user_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ClientFacingUser:
        """
        GET User details given the user_id.

        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        ClientFacingUser
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.get(
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingUser,
                    parse_obj_as(
                        type_=ClientFacingUser,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UserSuccessResponse:
        """
        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        UserSuccessResponse
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.delete(
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserSuccessResponse,
                    parse_obj_as(
                        type_=UserSuccessResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 patch(
        self,
        user_id: str,
        *,
        fallback_time_zone: typing.Optional[str] = OMIT,
        fallback_birth_date: typing.Optional[str] = OMIT,
        ingestion_start: typing.Optional[str] = OMIT,
        ingestion_end: typing.Optional[str] = OMIT,
        client_user_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Parameters
        ----------
        user_id : str

        fallback_time_zone : typing.Optional[str]

                Fallback time zone of the user, in the form of a valid IANA tzdatabase identifier (e.g., `Europe/London` or `America/Los_Angeles`).
                Used when pulling data from sources that are completely time zone agnostic (e.g., all time is relative to UTC clock, without any time zone attributions on data points).


        fallback_birth_date : typing.Optional[str]
            Fallback date of birth of the user, in YYYY-mm-dd format. Used for calculating max heartrate for providers that don not provide users' age.

        ingestion_start : typing.Optional[str]
            Starting bound for user data ingestion. Data older than this date will not be ingested.

        ingestion_end : typing.Optional[str]
            Ending bound for user data ingestion. Data from this date or later will not be ingested and the connection will be deregistered.

        client_user_id : typing.Optional[str]
            A unique ID representing the end user. Typically this will be a user ID from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.patch(
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}",
            method="PATCH",
            json={
                "fallback_time_zone": fallback_time_zone,
                "fallback_birth_date": fallback_birth_date,
                "ingestion_start": ingestion_start,
                "ingestion_end": ingestion_end,
                "client_user_id": client_user_id,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_latest_user_info(
        self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UserInfo:
        """
        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        UserInfo
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.get_latest_user_info(
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/info/latest",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserInfo,
                    parse_obj_as(
                        type_=UserInfo,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 create_insurance(
        self,
        user_id: str,
        *,
        payor_code: str,
        member_id: str,
        relationship: ResponsibleRelationship,
        insured: VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails,
        group_id: typing.Optional[str] = OMIT,
        guarantor: typing.Optional[GuarantorDetails] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClientFacingInsurance:
        """
        Parameters
        ----------
        user_id : str

        payor_code : str

        member_id : str

        relationship : ResponsibleRelationship

        insured : VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails

        group_id : typing.Optional[str]

        guarantor : typing.Optional[GuarantorDetails]

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

        Returns
        -------
        ClientFacingInsurance
            Successful Response

        Examples
        --------
        import asyncio

        from vital import (
            Address,
            AsyncVital,
            Gender,
            ResponsibleRelationship,
            VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails,
        )

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.create_insurance(
                user_id="user_id",
                payor_code="payor_code",
                member_id="member_id",
                relationship=ResponsibleRelationship.SELF,
                insured=VitalCoreSchemasDbSchemasLabTestInsurancePersonDetails(
                    first_name="first_name",
                    last_name="last_name",
                    gender=Gender.FEMALE,
                    address=Address(
                        first_line="first_line",
                        country="country",
                        zip="zip",
                        city="city",
                        state="state",
                    ),
                    dob="dob",
                    email="email",
                    phone_number="phone_number",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/insurance",
            method="POST",
            json={
                "payor_code": payor_code,
                "member_id": member_id,
                "group_id": group_id,
                "relationship": relationship,
                "insured": insured,
                "guarantor": guarantor,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingInsurance,
                    parse_obj_as(
                        type_=ClientFacingInsurance,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_latest_insurance(
        self, user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ClientFacingInsurance:
        """
        Parameters
        ----------
        user_id : str

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

        Returns
        -------
        ClientFacingInsurance
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.get_latest_insurance(
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/insurance/latest",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingInsurance,
                    parse_obj_as(
                        type_=ClientFacingInsurance,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 upsert_user_info(
        self,
        user_id: str,
        *,
        first_name: str,
        last_name: str,
        email: str,
        phone_number: str,
        gender: str,
        dob: str,
        address: Address,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserInfo:
        """
        Parameters
        ----------
        user_id : str

        first_name : str

        last_name : str

        email : str

        phone_number : str

        gender : str

        dob : str

        address : Address

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

        Returns
        -------
        UserInfo
            Successful Response

        Examples
        --------
        import asyncio

        from vital import Address, AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.upsert_user_info(
                user_id="user_id",
                first_name="first_name",
                last_name="last_name",
                email="email",
                phone_number="phone_number",
                gender="gender",
                dob="dob",
                address=Address(
                    first_line="first_line",
                    country="country",
                    zip="zip",
                    city="city",
                    state="state",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/info",
            method="PATCH",
            json={
                "first_name": first_name,
                "last_name": last_name,
                "email": email,
                "phone_number": phone_number,
                "gender": gender,
                "dob": dob,
                "address": address,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserInfo,
                    parse_obj_as(
                        type_=UserInfo,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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_by_client_user_id(
        self, client_user_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ClientFacingUser:
        """
        GET user_id from client_user_id.

        Parameters
        ----------
        client_user_id : str
            A unique ID representing the end user. Typically this will be a user ID number from your application. Personally identifiable information, such as an email address or phone number, should not be used in the client_user_id.

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

        Returns
        -------
        ClientFacingUser
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.get_by_client_user_id(
                client_user_id="client_user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/resolve/{jsonable_encoder(client_user_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ClientFacingUser,
                    parse_obj_as(
                        type_=ClientFacingUser,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 deregister_provider(
        self, user_id: str, provider: Providers, *, request_options: typing.Optional[RequestOptions] = None
    ) -> UserSuccessResponse:
        """
        Parameters
        ----------
        user_id : str

        provider : Providers
            Provider slug. e.g., `oura`, `fitbit`, `garmin`.

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

        Returns
        -------
        UserSuccessResponse
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital, Providers

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.deregister_provider(
                user_id="user_id",
                provider=Providers.OURA,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/{jsonable_encoder(user_id)}/{jsonable_encoder(provider)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserSuccessResponse,
                    parse_obj_as(
                        type_=UserSuccessResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 undo_delete(
        self,
        *,
        user_id: typing.Optional[str] = None,
        client_user_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserSuccessResponse:
        """
        Parameters
        ----------
        user_id : typing.Optional[str]
            User ID to undo deletion. Mutually exclusive with `client_user_id`.

        client_user_id : typing.Optional[str]
            Client User ID to undo deletion. Mutually exclusive with `user_id`.

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

        Returns
        -------
        UserSuccessResponse
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.undo_delete()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v2/user/undo_delete",
            method="POST",
            params={
                "user_id": user_id,
                "client_user_id": client_user_id,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserSuccessResponse,
                    parse_obj_as(
                        type_=UserSuccessResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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 refresh(
        self,
        user_id: str,
        *,
        timeout: typing.Optional[float] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UserRefreshSuccessResponse:
        """
        Trigger a manual refresh for a specific user

        Parameters
        ----------
        user_id : str

        timeout : typing.Optional[float]

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

        Returns
        -------
        UserRefreshSuccessResponse
            Successful Response

        Examples
        --------
        import asyncio

        from vital import AsyncVital

        client = AsyncVital(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.user.refresh(
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/user/refresh/{jsonable_encoder(user_id)}",
            method="POST",
            params={
                "timeout": timeout,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UserRefreshSuccessResponse,
                    parse_obj_as(
                        type_=UserRefreshSuccessResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _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)
