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

import typing
import uuid

from .....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .....core.request_options import RequestOptions
from ....commons.types.page_token import PageToken
from ....commons.types.sort_direction import SortDirection
from ....commons.types.state import State
from ..v_2.types.contract_sort_field import ContractSortField
from ..v_2.types.contract_status import ContractStatus
from .raw_client import AsyncRawV3Client, RawV3Client
from .types.contract_create_union import ContractCreateUnion
from .types.contract_id import ContractId
from .types.contract_service_facility import ContractServiceFacility
from .types.contract_service_facility_id import ContractServiceFacilityId
from .types.contract_type import ContractType
from .types.contract_update_union import ContractUpdateUnion
from .types.contract_with_providers_union import ContractWithProvidersUnion
from .types.contracting_provider_id import ContractingProviderId
from .types.contracts_page import ContractsPage
from .types.rendering_providerid import RenderingProviderid

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


class V3Client:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawV3Client(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawV3Client
        """
        return self._raw_client

    def get(
        self, contract_id: ContractId, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ContractWithProvidersUnion:
        """
        Parameters
        ----------
        contract_id : ContractId

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

        Returns
        -------
        ContractWithProvidersUnion

        Examples
        --------
        import uuid

        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.contracts.v_3.get(
            contract_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._raw_client.get(contract_id, request_options=request_options)
        return _response.data

    def get_multi(
        self,
        *,
        page_token: typing.Optional[PageToken] = None,
        limit: typing.Optional[int] = None,
        type: typing.Optional[ContractType] = None,
        contracting_provider_id: typing.Optional[ContractingProviderId] = None,
        rendering_provider_ids: typing.Optional[
            typing.Union[RenderingProviderid, typing.Sequence[RenderingProviderid]]
        ] = None,
        payer_names: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        states: typing.Optional[typing.Union[State, typing.Sequence[State]]] = None,
        contract_status: typing.Optional[ContractStatus] = None,
        sort: typing.Optional[ContractSortField] = None,
        sort_direction: typing.Optional[SortDirection] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ContractsPage:
        """
        Parameters
        ----------
        page_token : typing.Optional[PageToken]

        limit : typing.Optional[int]
            Max number of contracts returned. Defaults to 1000. Max is 1000.

        type : typing.Optional[ContractType]
            The type of contract

        contracting_provider_id : typing.Optional[ContractingProviderId]

        rendering_provider_ids : typing.Optional[typing.Union[RenderingProviderid, typing.Sequence[RenderingProviderid]]]

        payer_names : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter to contracts that include any of the included payer names.

        states : typing.Optional[typing.Union[State, typing.Sequence[State]]]

        contract_status : typing.Optional[ContractStatus]
            The status of the contract. Defaults to `pending`

        sort : typing.Optional[ContractSortField]
            Potentially sort by a contract related attribute.  Defaults to created_at

        sort_direction : typing.Optional[SortDirection]
            Direction of sort, defaulting to desc

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

        Returns
        -------
        ContractsPage

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

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.contracts.v_3.get_multi()
        """
        _response = self._raw_client.get_multi(
            page_token=page_token,
            limit=limit,
            type=type,
            contracting_provider_id=contracting_provider_id,
            rendering_provider_ids=rendering_provider_ids,
            payer_names=payer_names,
            states=states,
            contract_status=contract_status,
            sort=sort,
            sort_direction=sort_direction,
            request_options=request_options,
        )
        return _response.data

    def create(
        self, *, request: ContractCreateUnion, request_options: typing.Optional[RequestOptions] = None
    ) -> ContractWithProvidersUnion:
        """
        Creates a new contract within the user's current organization

        Parameters
        ----------
        request : ContractCreateUnion

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

        Returns
        -------
        ContractWithProvidersUnion

        Examples
        --------
        import uuid

        from candid import CandidApiClient
        from candid.resources.commons import Regions_States, State
        from candid.resources.contracts.resources.v_2 import InsuranceTypes
        from candid.resources.contracts.resources.v_3 import (
            ContractCreateUnion_Professional,
            ContractType,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.contracts.v_3.create(
            request=ContractCreateUnion_Professional(
                rendering_provider_ids=[
                    uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    )
                ],
                contract_type=ContractType.PROFESSIONAL,
                contracting_provider_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                payer_uuid=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                effective_date="effective_date",
                regions=Regions_States(
                    states=[State.AA, State.AA],
                ),
                commercial_insurance_types=InsuranceTypes(),
                medicare_insurance_types=InsuranceTypes(),
                medicaid_insurance_types=InsuranceTypes(),
            ),
        )
        """
        _response = self._raw_client.create(request=request, request_options=request_options)
        return _response.data

    def delete(self, contract_id: ContractId, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Parameters
        ----------
        contract_id : ContractId

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

        Returns
        -------
        None

        Examples
        --------
        import uuid

        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.contracts.v_3.delete(
            contract_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._raw_client.delete(contract_id, request_options=request_options)
        return _response.data

    def update(
        self,
        contract_id: ContractId,
        *,
        request: ContractUpdateUnion,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ContractWithProvidersUnion:
        """
        Parameters
        ----------
        contract_id : ContractId

        request : ContractUpdateUnion

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

        Returns
        -------
        ContractWithProvidersUnion

        Examples
        --------
        import uuid

        from candid import CandidApiClient
        from candid.resources.contracts.resources.v_3 import (
            ContractUpdateUnion_Professional,
        )

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.contracts.v_3.update(
            contract_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            request=ContractUpdateUnion_Professional(),
        )
        """
        _response = self._raw_client.update(contract_id, request=request, request_options=request_options)
        return _response.data

    def create_contract_service_facility(
        self,
        contract_id: ContractId,
        *,
        service_facility_id: uuid.UUID,
        provider_ids: typing.Set[uuid.UUID],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ContractServiceFacility:
        """
        Parameters
        ----------
        contract_id : ContractId

        service_facility_id : uuid.UUID
            The UUID of the service facility

        provider_ids : typing.Set[uuid.UUID]
            The providers who are authorized under the contract

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

        Returns
        -------
        ContractServiceFacility

        Examples
        --------
        import uuid

        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.contracts.v_3.create_contract_service_facility(
            contract_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            service_facility_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            provider_ids={
                uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                )
            },
        )
        """
        _response = self._raw_client.create_contract_service_facility(
            contract_id,
            service_facility_id=service_facility_id,
            provider_ids=provider_ids,
            request_options=request_options,
        )
        return _response.data

    def update_contract_service_facility(
        self,
        contract_id: ContractId,
        contract_service_facility_id: ContractServiceFacilityId,
        *,
        service_facility_id: typing.Optional[uuid.UUID] = OMIT,
        provider_ids: typing.Optional[typing.Set[uuid.UUID]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ContractServiceFacility:
        """
        Parameters
        ----------
        contract_id : ContractId

        contract_service_facility_id : ContractServiceFacilityId

        service_facility_id : typing.Optional[uuid.UUID]
            The UUID of the service facility

        provider_ids : typing.Optional[typing.Set[uuid.UUID]]
            The providers who are authorized under the contract

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

        Returns
        -------
        ContractServiceFacility

        Examples
        --------
        import uuid

        from candid import CandidApiClient

        client = CandidApiClient(
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.contracts.v_3.update_contract_service_facility(
            contract_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
            contract_service_facility_id=uuid.UUID(
                "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
            ),
        )
        """
        _response = self._raw_client.update_contract_service_facility(
            contract_id,
            contract_service_facility_id,
            service_facility_id=service_facility_id,
            provider_ids=provider_ids,
            request_options=request_options,
        )
        return _response.data


class AsyncV3Client:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawV3Client(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawV3Client
        """
        return self._raw_client

    async def get(
        self, contract_id: ContractId, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ContractWithProvidersUnion:
        """
        Parameters
        ----------
        contract_id : ContractId

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

        Returns
        -------
        ContractWithProvidersUnion

        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.contracts.v_3.get(
                contract_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


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

    async def get_multi(
        self,
        *,
        page_token: typing.Optional[PageToken] = None,
        limit: typing.Optional[int] = None,
        type: typing.Optional[ContractType] = None,
        contracting_provider_id: typing.Optional[ContractingProviderId] = None,
        rendering_provider_ids: typing.Optional[
            typing.Union[RenderingProviderid, typing.Sequence[RenderingProviderid]]
        ] = None,
        payer_names: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        states: typing.Optional[typing.Union[State, typing.Sequence[State]]] = None,
        contract_status: typing.Optional[ContractStatus] = None,
        sort: typing.Optional[ContractSortField] = None,
        sort_direction: typing.Optional[SortDirection] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ContractsPage:
        """
        Parameters
        ----------
        page_token : typing.Optional[PageToken]

        limit : typing.Optional[int]
            Max number of contracts returned. Defaults to 1000. Max is 1000.

        type : typing.Optional[ContractType]
            The type of contract

        contracting_provider_id : typing.Optional[ContractingProviderId]

        rendering_provider_ids : typing.Optional[typing.Union[RenderingProviderid, typing.Sequence[RenderingProviderid]]]

        payer_names : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter to contracts that include any of the included payer names.

        states : typing.Optional[typing.Union[State, typing.Sequence[State]]]

        contract_status : typing.Optional[ContractStatus]
            The status of the contract. Defaults to `pending`

        sort : typing.Optional[ContractSortField]
            Potentially sort by a contract related attribute.  Defaults to created_at

        sort_direction : typing.Optional[SortDirection]
            Direction of sort, defaulting to desc

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

        Returns
        -------
        ContractsPage

        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.contracts.v_3.get_multi()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_multi(
            page_token=page_token,
            limit=limit,
            type=type,
            contracting_provider_id=contracting_provider_id,
            rendering_provider_ids=rendering_provider_ids,
            payer_names=payer_names,
            states=states,
            contract_status=contract_status,
            sort=sort,
            sort_direction=sort_direction,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self, *, request: ContractCreateUnion, request_options: typing.Optional[RequestOptions] = None
    ) -> ContractWithProvidersUnion:
        """
        Creates a new contract within the user's current organization

        Parameters
        ----------
        request : ContractCreateUnion

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

        Returns
        -------
        ContractWithProvidersUnion

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

        from candid import AsyncCandidApiClient
        from candid.resources.commons import Regions_States, State
        from candid.resources.contracts.resources.v_2 import InsuranceTypes
        from candid.resources.contracts.resources.v_3 import (
            ContractCreateUnion_Professional,
            ContractType,
        )

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


        async def main() -> None:
            await client.contracts.v_3.create(
                request=ContractCreateUnion_Professional(
                    rendering_provider_ids=[
                        uuid.UUID(
                            "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                        )
                    ],
                    contract_type=ContractType.PROFESSIONAL,
                    contracting_provider_id=uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    ),
                    payer_uuid=uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    ),
                    effective_date="effective_date",
                    regions=Regions_States(
                        states=[State.AA, State.AA],
                    ),
                    commercial_insurance_types=InsuranceTypes(),
                    medicare_insurance_types=InsuranceTypes(),
                    medicaid_insurance_types=InsuranceTypes(),
                ),
            )


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

    async def delete(self, contract_id: ContractId, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Parameters
        ----------
        contract_id : ContractId

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

        Returns
        -------
        None

        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.contracts.v_3.delete(
                contract_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


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

    async def update(
        self,
        contract_id: ContractId,
        *,
        request: ContractUpdateUnion,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ContractWithProvidersUnion:
        """
        Parameters
        ----------
        contract_id : ContractId

        request : ContractUpdateUnion

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

        Returns
        -------
        ContractWithProvidersUnion

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

        from candid import AsyncCandidApiClient
        from candid.resources.contracts.resources.v_3 import (
            ContractUpdateUnion_Professional,
        )

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


        async def main() -> None:
            await client.contracts.v_3.update(
                contract_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                request=ContractUpdateUnion_Professional(),
            )


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

    async def create_contract_service_facility(
        self,
        contract_id: ContractId,
        *,
        service_facility_id: uuid.UUID,
        provider_ids: typing.Set[uuid.UUID],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ContractServiceFacility:
        """
        Parameters
        ----------
        contract_id : ContractId

        service_facility_id : uuid.UUID
            The UUID of the service facility

        provider_ids : typing.Set[uuid.UUID]
            The providers who are authorized under the contract

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

        Returns
        -------
        ContractServiceFacility

        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.contracts.v_3.create_contract_service_facility(
                contract_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                service_facility_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                provider_ids={
                    uuid.UUID(
                        "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                    )
                },
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_contract_service_facility(
            contract_id,
            service_facility_id=service_facility_id,
            provider_ids=provider_ids,
            request_options=request_options,
        )
        return _response.data

    async def update_contract_service_facility(
        self,
        contract_id: ContractId,
        contract_service_facility_id: ContractServiceFacilityId,
        *,
        service_facility_id: typing.Optional[uuid.UUID] = OMIT,
        provider_ids: typing.Optional[typing.Set[uuid.UUID]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ContractServiceFacility:
        """
        Parameters
        ----------
        contract_id : ContractId

        contract_service_facility_id : ContractServiceFacilityId

        service_facility_id : typing.Optional[uuid.UUID]
            The UUID of the service facility

        provider_ids : typing.Optional[typing.Set[uuid.UUID]]
            The providers who are authorized under the contract

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

        Returns
        -------
        ContractServiceFacility

        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.contracts.v_3.update_contract_service_facility(
                contract_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
                contract_service_facility_id=uuid.UUID(
                    "d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_contract_service_facility(
            contract_id,
            contract_service_facility_id,
            service_facility_id=service_facility_id,
            provider_ids=provider_ids,
            request_options=request_options,
        )
        return _response.data
