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

import typing
from json.decoder import JSONDecodeError

from .....core.api_error import ApiError
from .....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .....core.pydantic_utilities import pydantic_v1
from .....core.request_options import RequestOptions
from ....commons.types.encounter_id import EncounterId
from .types.billing_note import BillingNote

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


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

    def create(
        self, *, encounter_id: EncounterId, text: str, request_options: typing.Optional[RequestOptions] = None
    ) -> BillingNote:
        """
        Parameters
        ----------
        encounter_id : EncounterId

        text : str
            Empty string not allowed.

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

        Returns
        -------
        BillingNote

        Examples
        --------
        import uuid

        from candid.client import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.billing_notes.v_2.create(
            encounter_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            text="string",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/billing_notes/v2",
            method="POST",
            json={"encounter_id": encounter_id, "text": text},
            request_options=request_options,
            omit=OMIT,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(BillingNote, _response_json)  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)


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

    async def create(
        self, *, encounter_id: EncounterId, text: str, request_options: typing.Optional[RequestOptions] = None
    ) -> BillingNote:
        """
        Parameters
        ----------
        encounter_id : EncounterId

        text : str
            Empty string not allowed.

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

        Returns
        -------
        BillingNote

        Examples
        --------
        import uuid

        from candid.client import AsyncCandidApiClient

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        await client.billing_notes.v_2.create(
            encounter_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            text="string",
        )
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/billing_notes/v2",
            method="POST",
            json={"encounter_id": encounter_id, "text": text},
            request_options=request_options,
            omit=OMIT,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return pydantic_v1.parse_obj_as(BillingNote, _response_json)  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)
