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

from .....core.client_wrapper import SyncClientWrapper
from ....commons.types.charge_capture_bundle_id import ChargeCaptureBundleId
import typing
from .....core.request_options import RequestOptions
from .types.charge_capture_bundle import ChargeCaptureBundle
from .....core.jsonable_encoder import jsonable_encoder
from json.decoder import JSONDecodeError
from .....core.api_error import ApiError
from .....core.pydantic_utilities import parse_obj_as
from ....commons.errors.not_implemented_error import NotImplementedError
from ....commons.types.not_implemented_error_message import NotImplementedErrorMessage
from ....commons.types.page_token import PageToken
from .types.charge_capture_bundle_status import ChargeCaptureBundleStatus
from ....charge_capture.resources.v_1.types.charge_capture_status import ChargeCaptureStatus
import datetime as dt
from .types.charge_capture_bundle_page import ChargeCaptureBundlePage
from .....core.client_wrapper import AsyncClientWrapper


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

    def get(
        self,
        charge_capture_bundle_id: ChargeCaptureBundleId,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChargeCaptureBundle:
        """
        Parameters
        ----------
        charge_capture_bundle_id : ChargeCaptureBundleId

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

        Returns
        -------
        ChargeCaptureBundle

        Examples
        --------
        import uuid

        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.charge_capture_bundles.v_1.get(
            charge_capture_bundle_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/charge_capture_bundle/v1/{jsonable_encoder(charge_capture_bundle_id)}",
            base_url=self._client_wrapper.get_environment().candid_api,
            method="GET",
            request_options=request_options,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return typing.cast(
                ChargeCaptureBundle,
                parse_obj_as(
                    type_=ChargeCaptureBundle,  # type: ignore
                    object_=_response_json,
                ),
            )
        if "errorName" in _response_json:
            if _response_json["errorName"] == "NotImplementedError":
                raise NotImplementedError(
                    typing.cast(
                        NotImplementedErrorMessage,
                        parse_obj_as(
                            type_=NotImplementedErrorMessage,  # type: ignore
                            object_=_response_json["content"],
                        ),
                    )
                )
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def resubmit(
        self,
        charge_capture_bundle_id: ChargeCaptureBundleId,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChargeCaptureBundle:
        """
        Parameters
        ----------
        charge_capture_bundle_id : ChargeCaptureBundleId

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

        Returns
        -------
        ChargeCaptureBundle

        Examples
        --------
        import uuid

        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.charge_capture_bundles.v_1.resubmit(
            charge_capture_bundle_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"api/charge_capture_bundle/v1/{jsonable_encoder(charge_capture_bundle_id)}",
            base_url=self._client_wrapper.get_environment().candid_api,
            method="POST",
            request_options=request_options,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return typing.cast(
                ChargeCaptureBundle,
                parse_obj_as(
                    type_=ChargeCaptureBundle,  # type: ignore
                    object_=_response_json,
                ),
            )
        if "errorName" in _response_json:
            if _response_json["errorName"] == "NotImplementedError":
                raise NotImplementedError(
                    typing.cast(
                        NotImplementedErrorMessage,
                        parse_obj_as(
                            type_=NotImplementedErrorMessage,  # type: ignore
                            object_=_response_json["content"],
                        ),
                    )
                )
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def get_all(
        self,
        *,
        limit: typing.Optional[int] = None,
        page_token: typing.Optional[PageToken] = None,
        patient_external_id: typing.Optional[str] = None,
        bundle_status: typing.Optional[ChargeCaptureBundleStatus] = None,
        charge_status: typing.Optional[ChargeCaptureStatus] = None,
        charge_external_id: typing.Optional[str] = None,
        date_of_service: typing.Optional[dt.date] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChargeCaptureBundlePage:
        """
        Parameters
        ----------
        limit : typing.Optional[int]
            Maximum number of entities per page, defaults to 100.

        page_token : typing.Optional[PageToken]

        patient_external_id : typing.Optional[str]
            The patient ID from the external EMR platform for the patient

        bundle_status : typing.Optional[ChargeCaptureBundleStatus]
            the status of the charge capture bundle, refers to whether it was able to create an encounter.

        charge_status : typing.Optional[ChargeCaptureStatus]
            the status of the charge captures

        charge_external_id : typing.Optional[str]
            A client-specified unique ID to associate with this encounter;
            for example, your internal encounter ID or a Dr. Chrono encounter ID.
            This field should not contain PHI.

        date_of_service : typing.Optional[dt.date]
            Date formatted as YYYY-MM-DD; eg: 2019-08-24.
            This date must be the local date in the timezone where the service occurred.

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

        Returns
        -------
        ChargeCaptureBundlePage

        Examples
        --------
        import datetime

        from candid import CandidApiClient
        from candid.resources.charge_capture.resources.v_1 import ChargeCaptureStatus
        from candid.resources.charge_capture_bundles.resources.v_1 import (
            ChargeCaptureBundleStatus,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.charge_capture_bundles.v_1.get_all(
            limit=1,
            page_token="eyJ0b2tlbiI6IjEiLCJwYWdlX3Rva2VuIjoiMiJ9",
            patient_external_id="string",
            bundle_status=ChargeCaptureBundleStatus.IN_PROGRESS,
            charge_status=ChargeCaptureStatus.PLANNED,
            charge_external_id="string",
            date_of_service=datetime.date.fromisoformat(
                "2023-01-15",
            ),
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "api/charge_capture_bundle/v1",
            base_url=self._client_wrapper.get_environment().candid_api,
            method="GET",
            params={
                "limit": limit,
                "page_token": page_token,
                "patient_external_id": patient_external_id,
                "bundle_status": bundle_status,
                "charge_status": charge_status,
                "charge_external_id": charge_external_id,
                "date_of_service": str(date_of_service) if date_of_service is not None else None,
            },
            request_options=request_options,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return typing.cast(
                ChargeCaptureBundlePage,
                parse_obj_as(
                    type_=ChargeCaptureBundlePage,  # type: ignore
                    object_=_response_json,
                ),
            )
        if "errorName" in _response_json:
            if _response_json["errorName"] == "NotImplementedError":
                raise NotImplementedError(
                    typing.cast(
                        NotImplementedErrorMessage,
                        parse_obj_as(
                            type_=NotImplementedErrorMessage,  # type: ignore
                            object_=_response_json["content"],
                        ),
                    )
                )
        raise ApiError(status_code=_response.status_code, body=_response_json)


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

    async def get(
        self,
        charge_capture_bundle_id: ChargeCaptureBundleId,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChargeCaptureBundle:
        """
        Parameters
        ----------
        charge_capture_bundle_id : ChargeCaptureBundleId

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

        Returns
        -------
        ChargeCaptureBundle

        Examples
        --------
        import asyncio
        import uuid

        from candid import AsyncCandidApiClient

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.charge_capture_bundles.v_1.get(
                charge_capture_bundle_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/charge_capture_bundle/v1/{jsonable_encoder(charge_capture_bundle_id)}",
            base_url=self._client_wrapper.get_environment().candid_api,
            method="GET",
            request_options=request_options,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return typing.cast(
                ChargeCaptureBundle,
                parse_obj_as(
                    type_=ChargeCaptureBundle,  # type: ignore
                    object_=_response_json,
                ),
            )
        if "errorName" in _response_json:
            if _response_json["errorName"] == "NotImplementedError":
                raise NotImplementedError(
                    typing.cast(
                        NotImplementedErrorMessage,
                        parse_obj_as(
                            type_=NotImplementedErrorMessage,  # type: ignore
                            object_=_response_json["content"],
                        ),
                    )
                )
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def resubmit(
        self,
        charge_capture_bundle_id: ChargeCaptureBundleId,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChargeCaptureBundle:
        """
        Parameters
        ----------
        charge_capture_bundle_id : ChargeCaptureBundleId

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

        Returns
        -------
        ChargeCaptureBundle

        Examples
        --------
        import asyncio
        import uuid

        from candid import AsyncCandidApiClient

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.charge_capture_bundles.v_1.resubmit(
                charge_capture_bundle_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"api/charge_capture_bundle/v1/{jsonable_encoder(charge_capture_bundle_id)}",
            base_url=self._client_wrapper.get_environment().candid_api,
            method="POST",
            request_options=request_options,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return typing.cast(
                ChargeCaptureBundle,
                parse_obj_as(
                    type_=ChargeCaptureBundle,  # type: ignore
                    object_=_response_json,
                ),
            )
        if "errorName" in _response_json:
            if _response_json["errorName"] == "NotImplementedError":
                raise NotImplementedError(
                    typing.cast(
                        NotImplementedErrorMessage,
                        parse_obj_as(
                            type_=NotImplementedErrorMessage,  # type: ignore
                            object_=_response_json["content"],
                        ),
                    )
                )
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def get_all(
        self,
        *,
        limit: typing.Optional[int] = None,
        page_token: typing.Optional[PageToken] = None,
        patient_external_id: typing.Optional[str] = None,
        bundle_status: typing.Optional[ChargeCaptureBundleStatus] = None,
        charge_status: typing.Optional[ChargeCaptureStatus] = None,
        charge_external_id: typing.Optional[str] = None,
        date_of_service: typing.Optional[dt.date] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChargeCaptureBundlePage:
        """
        Parameters
        ----------
        limit : typing.Optional[int]
            Maximum number of entities per page, defaults to 100.

        page_token : typing.Optional[PageToken]

        patient_external_id : typing.Optional[str]
            The patient ID from the external EMR platform for the patient

        bundle_status : typing.Optional[ChargeCaptureBundleStatus]
            the status of the charge capture bundle, refers to whether it was able to create an encounter.

        charge_status : typing.Optional[ChargeCaptureStatus]
            the status of the charge captures

        charge_external_id : typing.Optional[str]
            A client-specified unique ID to associate with this encounter;
            for example, your internal encounter ID or a Dr. Chrono encounter ID.
            This field should not contain PHI.

        date_of_service : typing.Optional[dt.date]
            Date formatted as YYYY-MM-DD; eg: 2019-08-24.
            This date must be the local date in the timezone where the service occurred.

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

        Returns
        -------
        ChargeCaptureBundlePage

        Examples
        --------
        import asyncio
        import datetime

        from candid import AsyncCandidApiClient
        from candid.resources.charge_capture.resources.v_1 import ChargeCaptureStatus
        from candid.resources.charge_capture_bundles.resources.v_1 import (
            ChargeCaptureBundleStatus,
        )

        client = AsyncCandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.charge_capture_bundles.v_1.get_all(
                limit=1,
                page_token="eyJ0b2tlbiI6IjEiLCJwYWdlX3Rva2VuIjoiMiJ9",
                patient_external_id="string",
                bundle_status=ChargeCaptureBundleStatus.IN_PROGRESS,
                charge_status=ChargeCaptureStatus.PLANNED,
                charge_external_id="string",
                date_of_service=datetime.date.fromisoformat(
                    "2023-01-15",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "api/charge_capture_bundle/v1",
            base_url=self._client_wrapper.get_environment().candid_api,
            method="GET",
            params={
                "limit": limit,
                "page_token": page_token,
                "patient_external_id": patient_external_id,
                "bundle_status": bundle_status,
                "charge_status": charge_status,
                "charge_external_id": charge_external_id,
                "date_of_service": str(date_of_service) if date_of_service is not None else None,
            },
            request_options=request_options,
        )
        try:
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        if 200 <= _response.status_code < 300:
            return typing.cast(
                ChargeCaptureBundlePage,
                parse_obj_as(
                    type_=ChargeCaptureBundlePage,  # type: ignore
                    object_=_response_json,
                ),
            )
        if "errorName" in _response_json:
            if _response_json["errorName"] == "NotImplementedError":
                raise NotImplementedError(
                    typing.cast(
                        NotImplementedErrorMessage,
                        parse_obj_as(
                            type_=NotImplementedErrorMessage,  # type: ignore
                            object_=_response_json["content"],
                        ),
                    )
                )
        raise ApiError(status_code=_response.status_code, body=_response_json)
