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

import datetime as dt
import typing

from .......core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .......core.request_options import RequestOptions
from ....common.types.filter_query_string import FilterQueryString
from ....common.types.page_token import PageToken
from .raw_client import AsyncRawV1Client, RawV1Client
from .types.batch_eligibility_response import BatchEligibilityResponse
from .types.eligibility_check_page import EligibilityCheckPage
from .types.eligibility_recommendation import EligibilityRecommendation
from .types.eligibility_request import EligibilityRequest
from .types.eligibility_response import EligibilityResponse
from .types.payer_search_response import PayerSearchResponse
from .types.post_eligibility_recommendation_request import PostEligibilityRecommendationRequest
from .types.vote import Vote

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


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

    @property
    def with_raw_response(self) -> RawV1Client:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawV1Client
        """
        return self._raw_client

    def post(
        self, *, request: EligibilityRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> EligibilityResponse:
        """
        Sends real-time eligibility checks to payers through Stedi.

        Parameters
        ----------
        request : EligibilityRequest

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

        Returns
        -------
        EligibilityResponse

        Examples
        --------
        from candid import CandidApiClient
        from candid.resources.pre_encounter.resources.coverages.resources.v_1 import (
            MemberInfo,
        )
        from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
            EligibilityRequest,
            IndividualProvider,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.eligibility_checks.v_1.post(
            request=EligibilityRequest(
                payer_id="payer_id",
                provider=IndividualProvider(
                    npi="npi",
                ),
                subscriber=MemberInfo(
                    first_name="first_name",
                    last_name="last_name",
                ),
            ),
        )
        """
        _response = self._raw_client.post(request=request, request_options=request_options)
        return _response.data

    def batch(
        self, *, request: typing.Sequence[EligibilityRequest], request_options: typing.Optional[RequestOptions] = None
    ) -> BatchEligibilityResponse:
        """
        Sends a batch of eligibility checks to payers through Stedi.

        Parameters
        ----------
        request : typing.Sequence[EligibilityRequest]

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

        Returns
        -------
        BatchEligibilityResponse

        Examples
        --------
        from candid import CandidApiClient
        from candid.resources.pre_encounter.resources.coverages.resources.v_1 import (
            MemberInfo,
        )
        from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
            EligibilityRequest,
            IndividualProvider,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.eligibility_checks.v_1.batch(
            request=[
                EligibilityRequest(
                    payer_id="payer_id",
                    provider=IndividualProvider(
                        npi="npi",
                    ),
                    subscriber=MemberInfo(
                        first_name="first_name",
                        last_name="last_name",
                    ),
                ),
                EligibilityRequest(
                    payer_id="payer_id",
                    provider=IndividualProvider(
                        npi="npi",
                    ),
                    subscriber=MemberInfo(
                        first_name="first_name",
                        last_name="last_name",
                    ),
                ),
            ],
        )
        """
        _response = self._raw_client.batch(request=request, request_options=request_options)
        return _response.data

    def poll_batch(
        self,
        batch_id: str,
        *,
        page_token: typing.Optional[PageToken] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EligibilityCheckPage:
        """
        Polls the status of a batch eligibility check.

        Parameters
        ----------
        batch_id : str

        page_token : typing.Optional[PageToken]

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

        Returns
        -------
        EligibilityCheckPage

        Examples
        --------
        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.eligibility_checks.v_1.poll_batch(
            batch_id="batch_id",
        )
        """
        _response = self._raw_client.poll_batch(batch_id, page_token=page_token, request_options=request_options)
        return _response.data

    def payer_search(
        self,
        *,
        page_size: typing.Optional[int] = None,
        page_token: typing.Optional[PageToken] = None,
        query: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PayerSearchResponse:
        """
        Searches for payers that match the query parameters.

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

        page_token : typing.Optional[PageToken]

        query : typing.Optional[str]

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

        Returns
        -------
        PayerSearchResponse

        Examples
        --------
        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.eligibility_checks.v_1.payer_search()
        """
        _response = self._raw_client.payer_search(
            page_size=page_size, page_token=page_token, query=query, request_options=request_options
        )
        return _response.data

    def recommendation(
        self,
        *,
        filters: typing.Optional[FilterQueryString] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[EligibilityRecommendation]:
        """
        Gets recommendation for eligibility checks based on filters. This endpoint will retrieve all the latest eligibility recommendations for each
        eligibility recommendation type for the given filters. If you want to get a specific recommendation type, you can use the `type` query parameter.

        Parameters
        ----------
        filters : typing.Optional[FilterQueryString]

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

        Returns
        -------
        typing.List[EligibilityRecommendation]

        Examples
        --------
        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.eligibility_checks.v_1.recommendation()
        """
        _response = self._raw_client.recommendation(filters=filters, request_options=request_options)
        return _response.data

    def create_recommendation(
        self, *, request: PostEligibilityRecommendationRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> EligibilityRecommendation:
        """
        Create an eligibiilty recommendation based on the request.

        Parameters
        ----------
        request : PostEligibilityRecommendationRequest

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

        Returns
        -------
        EligibilityRecommendation

        Examples
        --------
        from candid import CandidApiClient
        from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
            EligibilityRecommendationPatientInfo,
            EligibilityRecommendationPayload_MedicareAdvantage,
            MedicareAdvantageRecommendationPayload,
            PostEligibilityRecommendationRequest,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.eligibility_checks.v_1.create_recommendation(
            request=PostEligibilityRecommendationRequest(
                eligibility_check_id="eligibility_check_id",
                patient=EligibilityRecommendationPatientInfo(),
                recommendation=EligibilityRecommendationPayload_MedicareAdvantage(
                    payload=MedicareAdvantageRecommendationPayload(),
                ),
            ),
        )
        """
        _response = self._raw_client.create_recommendation(request=request, request_options=request_options)
        return _response.data

    def vote_recommendation(
        self,
        recommendation_id: str,
        version: str,
        *,
        request: Vote,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EligibilityRecommendation:
        """
        Submit user feedback on an eligibility recommendation. The path must contain the next version number to prevent race conditions. For example, if the current version of the recommendation is n, you will need to send a request to this endpoint with `/{recommendation_id}/{n+1}/vote` to update the vote.

        Parameters
        ----------
        recommendation_id : str

        version : str

        request : Vote

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

        Returns
        -------
        EligibilityRecommendation

        Examples
        --------
        from candid import CandidApiClient
        from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
            Vote,
            VoteValue,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.eligibility_checks.v_1.vote_recommendation(
            recommendation_id="recommendation_id",
            version="version",
            request=Vote(
                user_id="user_id",
                value=VoteValue.UPVOTE,
            ),
        )
        """
        _response = self._raw_client.vote_recommendation(
            recommendation_id, version, request=request, request_options=request_options
        )
        return _response.data

    def get_multi(
        self,
        *,
        page_token: typing.Optional[PageToken] = None,
        limit: typing.Optional[int] = None,
        subscriber_member_id: typing.Optional[str] = None,
        payer_id: typing.Optional[str] = None,
        provider_npi: typing.Optional[str] = None,
        date_of_service: typing.Optional[str] = None,
        initiated_at_min: typing.Optional[dt.datetime] = None,
        initiated_at_max: typing.Optional[dt.datetime] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EligibilityCheckPage:
        """
        Parameters
        ----------
        page_token : typing.Optional[PageToken]

        limit : typing.Optional[int]

        subscriber_member_id : typing.Optional[str]

        payer_id : typing.Optional[str]

        provider_npi : typing.Optional[str]

        date_of_service : typing.Optional[str]

        initiated_at_min : typing.Optional[dt.datetime]

        initiated_at_max : typing.Optional[dt.datetime]

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

        Returns
        -------
        EligibilityCheckPage

        Examples
        --------
        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.pre_encounter.eligibility_checks.v_1.get_multi()
        """
        _response = self._raw_client.get_multi(
            page_token=page_token,
            limit=limit,
            subscriber_member_id=subscriber_member_id,
            payer_id=payer_id,
            provider_npi=provider_npi,
            date_of_service=date_of_service,
            initiated_at_min=initiated_at_min,
            initiated_at_max=initiated_at_max,
            request_options=request_options,
        )
        return _response.data


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

    @property
    def with_raw_response(self) -> AsyncRawV1Client:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawV1Client
        """
        return self._raw_client

    async def post(
        self, *, request: EligibilityRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> EligibilityResponse:
        """
        Sends real-time eligibility checks to payers through Stedi.

        Parameters
        ----------
        request : EligibilityRequest

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

        Returns
        -------
        EligibilityResponse

        Examples
        --------
        import asyncio

        from candid import AsyncCandidApiClient
        from candid.resources.pre_encounter.resources.coverages.resources.v_1 import (
            MemberInfo,
        )
        from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
            EligibilityRequest,
            IndividualProvider,
        )

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


        async def main() -> None:
            await client.pre_encounter.eligibility_checks.v_1.post(
                request=EligibilityRequest(
                    payer_id="payer_id",
                    provider=IndividualProvider(
                        npi="npi",
                    ),
                    subscriber=MemberInfo(
                        first_name="first_name",
                        last_name="last_name",
                    ),
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.post(request=request, request_options=request_options)
        return _response.data

    async def batch(
        self, *, request: typing.Sequence[EligibilityRequest], request_options: typing.Optional[RequestOptions] = None
    ) -> BatchEligibilityResponse:
        """
        Sends a batch of eligibility checks to payers through Stedi.

        Parameters
        ----------
        request : typing.Sequence[EligibilityRequest]

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

        Returns
        -------
        BatchEligibilityResponse

        Examples
        --------
        import asyncio

        from candid import AsyncCandidApiClient
        from candid.resources.pre_encounter.resources.coverages.resources.v_1 import (
            MemberInfo,
        )
        from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
            EligibilityRequest,
            IndividualProvider,
        )

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


        async def main() -> None:
            await client.pre_encounter.eligibility_checks.v_1.batch(
                request=[
                    EligibilityRequest(
                        payer_id="payer_id",
                        provider=IndividualProvider(
                            npi="npi",
                        ),
                        subscriber=MemberInfo(
                            first_name="first_name",
                            last_name="last_name",
                        ),
                    ),
                    EligibilityRequest(
                        payer_id="payer_id",
                        provider=IndividualProvider(
                            npi="npi",
                        ),
                        subscriber=MemberInfo(
                            first_name="first_name",
                            last_name="last_name",
                        ),
                    ),
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.batch(request=request, request_options=request_options)
        return _response.data

    async def poll_batch(
        self,
        batch_id: str,
        *,
        page_token: typing.Optional[PageToken] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EligibilityCheckPage:
        """
        Polls the status of a batch eligibility check.

        Parameters
        ----------
        batch_id : str

        page_token : typing.Optional[PageToken]

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

        Returns
        -------
        EligibilityCheckPage

        Examples
        --------
        import asyncio

        from candid import AsyncCandidApiClient

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


        async def main() -> None:
            await client.pre_encounter.eligibility_checks.v_1.poll_batch(
                batch_id="batch_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.poll_batch(batch_id, page_token=page_token, request_options=request_options)
        return _response.data

    async def payer_search(
        self,
        *,
        page_size: typing.Optional[int] = None,
        page_token: typing.Optional[PageToken] = None,
        query: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PayerSearchResponse:
        """
        Searches for payers that match the query parameters.

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

        page_token : typing.Optional[PageToken]

        query : typing.Optional[str]

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

        Returns
        -------
        PayerSearchResponse

        Examples
        --------
        import asyncio

        from candid import AsyncCandidApiClient

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


        async def main() -> None:
            await client.pre_encounter.eligibility_checks.v_1.payer_search()


        asyncio.run(main())
        """
        _response = await self._raw_client.payer_search(
            page_size=page_size, page_token=page_token, query=query, request_options=request_options
        )
        return _response.data

    async def recommendation(
        self,
        *,
        filters: typing.Optional[FilterQueryString] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[EligibilityRecommendation]:
        """
        Gets recommendation for eligibility checks based on filters. This endpoint will retrieve all the latest eligibility recommendations for each
        eligibility recommendation type for the given filters. If you want to get a specific recommendation type, you can use the `type` query parameter.

        Parameters
        ----------
        filters : typing.Optional[FilterQueryString]

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

        Returns
        -------
        typing.List[EligibilityRecommendation]

        Examples
        --------
        import asyncio

        from candid import AsyncCandidApiClient

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


        async def main() -> None:
            await client.pre_encounter.eligibility_checks.v_1.recommendation()


        asyncio.run(main())
        """
        _response = await self._raw_client.recommendation(filters=filters, request_options=request_options)
        return _response.data

    async def create_recommendation(
        self, *, request: PostEligibilityRecommendationRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> EligibilityRecommendation:
        """
        Create an eligibiilty recommendation based on the request.

        Parameters
        ----------
        request : PostEligibilityRecommendationRequest

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

        Returns
        -------
        EligibilityRecommendation

        Examples
        --------
        import asyncio

        from candid import AsyncCandidApiClient
        from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
            EligibilityRecommendationPatientInfo,
            EligibilityRecommendationPayload_MedicareAdvantage,
            MedicareAdvantageRecommendationPayload,
            PostEligibilityRecommendationRequest,
        )

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


        async def main() -> None:
            await client.pre_encounter.eligibility_checks.v_1.create_recommendation(
                request=PostEligibilityRecommendationRequest(
                    eligibility_check_id="eligibility_check_id",
                    patient=EligibilityRecommendationPatientInfo(),
                    recommendation=EligibilityRecommendationPayload_MedicareAdvantage(
                        payload=MedicareAdvantageRecommendationPayload(),
                    ),
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_recommendation(request=request, request_options=request_options)
        return _response.data

    async def vote_recommendation(
        self,
        recommendation_id: str,
        version: str,
        *,
        request: Vote,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EligibilityRecommendation:
        """
        Submit user feedback on an eligibility recommendation. The path must contain the next version number to prevent race conditions. For example, if the current version of the recommendation is n, you will need to send a request to this endpoint with `/{recommendation_id}/{n+1}/vote` to update the vote.

        Parameters
        ----------
        recommendation_id : str

        version : str

        request : Vote

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

        Returns
        -------
        EligibilityRecommendation

        Examples
        --------
        import asyncio

        from candid import AsyncCandidApiClient
        from candid.resources.pre_encounter.resources.eligibility_checks.resources.v_1 import (
            Vote,
            VoteValue,
        )

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


        async def main() -> None:
            await client.pre_encounter.eligibility_checks.v_1.vote_recommendation(
                recommendation_id="recommendation_id",
                version="version",
                request=Vote(
                    user_id="user_id",
                    value=VoteValue.UPVOTE,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.vote_recommendation(
            recommendation_id, version, request=request, request_options=request_options
        )
        return _response.data

    async def get_multi(
        self,
        *,
        page_token: typing.Optional[PageToken] = None,
        limit: typing.Optional[int] = None,
        subscriber_member_id: typing.Optional[str] = None,
        payer_id: typing.Optional[str] = None,
        provider_npi: typing.Optional[str] = None,
        date_of_service: typing.Optional[str] = None,
        initiated_at_min: typing.Optional[dt.datetime] = None,
        initiated_at_max: typing.Optional[dt.datetime] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EligibilityCheckPage:
        """
        Parameters
        ----------
        page_token : typing.Optional[PageToken]

        limit : typing.Optional[int]

        subscriber_member_id : typing.Optional[str]

        payer_id : typing.Optional[str]

        provider_npi : typing.Optional[str]

        date_of_service : typing.Optional[str]

        initiated_at_min : typing.Optional[dt.datetime]

        initiated_at_max : typing.Optional[dt.datetime]

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

        Returns
        -------
        EligibilityCheckPage

        Examples
        --------
        import asyncio

        from candid import AsyncCandidApiClient

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


        async def main() -> None:
            await client.pre_encounter.eligibility_checks.v_1.get_multi()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_multi(
            page_token=page_token,
            limit=limit,
            subscriber_member_id=subscriber_member_id,
            payer_id=payer_id,
            provider_npi=provider_npi,
            date_of_service=date_of_service,
            initiated_at_min=initiated_at_min,
            initiated_at_max=initiated_at_max,
            request_options=request_options,
        )
        return _response.data
