# 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 ....common.errors.bad_request_error import BadRequestError
from ....common.types.error_base import ErrorBase
from ....common.types.page_token import PageToken
from ....common.types.sort_direction import SortDirection
from .types.appointment_list_page import AppointmentListPage
from .types.filter_query_string import FilterQueryString
from .types.patient_list_page import PatientListPage


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

    def get_patient_list(
        self,
        *,
        page_token: typing.Optional[PageToken] = None,
        limit: typing.Optional[int] = None,
        sort_field: typing.Optional[str] = None,
        sort_direction: typing.Optional[SortDirection] = None,
        filters: typing.Optional[FilterQueryString] = None,
        request_options: typing.Optional[RequestOptions] = None
    ) -> PatientListPage:
        """
        Gets patients with dependent objects for patients that match the query parameters.

        Parameters
        ----------
        page_token : typing.Optional[PageToken]

        limit : typing.Optional[int]

        sort_field : typing.Optional[str]

        sort_direction : typing.Optional[SortDirection]
            Defaults to ascending.

        filters : typing.Optional[FilterQueryString]

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

        Returns
        -------
        PatientListPage

        Examples
        --------
        from candid.client import CandidApiClient
        from candid.resources.pre_encounter import SortDirection

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.lists.v_1.get_patient_list(
            page_token="string",
            limit=1,
            sort_field="string",
            sort_direction=SortDirection.ASC,
            filters="string",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "lists/v1/patient",
            base_url=self._client_wrapper.get_environment().pre_encounter,
            method="GET",
            params={
                "page_token": page_token,
                "limit": limit,
                "sort_field": sort_field,
                "sort_direction": sort_direction,
                "filters": filters,
            },
            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 pydantic_v1.parse_obj_as(PatientListPage, _response_json)  # type: ignore
        if "errorName" in _response_json:
            if _response_json["errorName"] == "BadRequestError":
                raise BadRequestError(pydantic_v1.parse_obj_as(ErrorBase, _response_json["content"]))  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def get_appointment_list(
        self,
        *,
        sort_field: typing.Optional[str] = None,
        sort_direction: typing.Optional[SortDirection] = None,
        limit: typing.Optional[int] = None,
        page_token: typing.Optional[PageToken] = None,
        filters: typing.Optional[FilterQueryString] = None,
        request_options: typing.Optional[RequestOptions] = None
    ) -> AppointmentListPage:
        """
        Searches for appointments that match the query parameters.

        Parameters
        ----------
        sort_field : typing.Optional[str]
            The string path to the field to order by. Defaults to appointment.startTimestamp. Path values are camelCase.

        sort_direction : typing.Optional[SortDirection]
            Defaults to asc.

        limit : typing.Optional[int]
            Defaults to 100.

        page_token : typing.Optional[PageToken]

        filters : typing.Optional[FilterQueryString]

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

        Returns
        -------
        AppointmentListPage

        Examples
        --------
        from candid.client import CandidApiClient
        from candid.resources.pre_encounter import SortDirection

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.lists.v_1.get_appointment_list(
            sort_field="string",
            sort_direction=SortDirection.ASC,
            limit=1,
            page_token="string",
            filters="string",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "lists/v1/appointment",
            base_url=self._client_wrapper.get_environment().pre_encounter,
            method="GET",
            params={
                "sort_field": sort_field,
                "sort_direction": sort_direction,
                "limit": limit,
                "page_token": page_token,
                "filters": filters,
            },
            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 pydantic_v1.parse_obj_as(AppointmentListPage, _response_json)  # type: ignore
        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_patient_list(
        self,
        *,
        page_token: typing.Optional[PageToken] = None,
        limit: typing.Optional[int] = None,
        sort_field: typing.Optional[str] = None,
        sort_direction: typing.Optional[SortDirection] = None,
        filters: typing.Optional[FilterQueryString] = None,
        request_options: typing.Optional[RequestOptions] = None
    ) -> PatientListPage:
        """
        Gets patients with dependent objects for patients that match the query parameters.

        Parameters
        ----------
        page_token : typing.Optional[PageToken]

        limit : typing.Optional[int]

        sort_field : typing.Optional[str]

        sort_direction : typing.Optional[SortDirection]
            Defaults to ascending.

        filters : typing.Optional[FilterQueryString]

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

        Returns
        -------
        PatientListPage

        Examples
        --------
        import asyncio

        from candid.client import AsyncCandidApiClient
        from candid.resources.pre_encounter import SortDirection

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


        async def main() -> None:
            await client.pre_encounter.lists.v_1.get_patient_list(
                page_token="string",
                limit=1,
                sort_field="string",
                sort_direction=SortDirection.ASC,
                filters="string",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "lists/v1/patient",
            base_url=self._client_wrapper.get_environment().pre_encounter,
            method="GET",
            params={
                "page_token": page_token,
                "limit": limit,
                "sort_field": sort_field,
                "sort_direction": sort_direction,
                "filters": filters,
            },
            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 pydantic_v1.parse_obj_as(PatientListPage, _response_json)  # type: ignore
        if "errorName" in _response_json:
            if _response_json["errorName"] == "BadRequestError":
                raise BadRequestError(pydantic_v1.parse_obj_as(ErrorBase, _response_json["content"]))  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def get_appointment_list(
        self,
        *,
        sort_field: typing.Optional[str] = None,
        sort_direction: typing.Optional[SortDirection] = None,
        limit: typing.Optional[int] = None,
        page_token: typing.Optional[PageToken] = None,
        filters: typing.Optional[FilterQueryString] = None,
        request_options: typing.Optional[RequestOptions] = None
    ) -> AppointmentListPage:
        """
        Searches for appointments that match the query parameters.

        Parameters
        ----------
        sort_field : typing.Optional[str]
            The string path to the field to order by. Defaults to appointment.startTimestamp. Path values are camelCase.

        sort_direction : typing.Optional[SortDirection]
            Defaults to asc.

        limit : typing.Optional[int]
            Defaults to 100.

        page_token : typing.Optional[PageToken]

        filters : typing.Optional[FilterQueryString]

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

        Returns
        -------
        AppointmentListPage

        Examples
        --------
        import asyncio

        from candid.client import AsyncCandidApiClient
        from candid.resources.pre_encounter import SortDirection

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


        async def main() -> None:
            await client.pre_encounter.lists.v_1.get_appointment_list(
                sort_field="string",
                sort_direction=SortDirection.ASC,
                limit=1,
                page_token="string",
                filters="string",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "lists/v1/appointment",
            base_url=self._client_wrapper.get_environment().pre_encounter,
            method="GET",
            params={
                "sort_field": sort_field,
                "sort_direction": sort_direction,
                "limit": limit,
                "page_token": page_token,
                "filters": filters,
            },
            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 pydantic_v1.parse_obj_as(AppointmentListPage, _response_json)  # type: ignore
        raise ApiError(status_code=_response.status_code, body=_response_json)
