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

from __future__ import annotations

import typing

import httpx
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .core.request_options import RequestOptions
from .environment import SchematicEnvironment
from .raw_base_client import AsyncRawBaseSchematic, RawBaseSchematic

if typing.TYPE_CHECKING:
    from .accesstokens.client import AccesstokensClient, AsyncAccesstokensClient
    from .accounts.client import AccountsClient, AsyncAccountsClient
    from .billing.client import AsyncBillingClient, BillingClient
    from .checkout.client import AsyncCheckoutClient, CheckoutClient
    from .companies.client import AsyncCompaniesClient, CompaniesClient
    from .components.client import AsyncComponentsClient, ComponentsClient
    from .credits.client import AsyncCreditsClient, CreditsClient
    from .crm.client import AsyncCrmClient, CrmClient
    from .dataexports.client import AsyncDataexportsClient, DataexportsClient
    from .entitlements.client import AsyncEntitlementsClient, EntitlementsClient
    from .events.client import AsyncEventsClient, EventsClient
    from .features.client import AsyncFeaturesClient, FeaturesClient
    from .plangroups.client import AsyncPlangroupsClient, PlangroupsClient
    from .plans.client import AsyncPlansClient, PlansClient
    from .webhooks.client import AsyncWebhooksClient, WebhooksClient


class BaseSchematic:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : typing.Optional[str]
        The base url to use for requests from the client.

    environment : SchematicEnvironment
        The environment to use for requests from the client. from .environment import SchematicEnvironment



        Defaults to SchematicEnvironment.DEFAULT



    api_key : str
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.Client]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    Examples
    --------
    from schematic import Schematic

    client = Schematic(
        api_key="YOUR_API_KEY",
    )
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: SchematicEnvironment = SchematicEnvironment.DEFAULT,
        api_key: str,
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.Client] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        self._client_wrapper = SyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            api_key=api_key,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.Client(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
        )
        self._raw_client = RawBaseSchematic(client_wrapper=self._client_wrapper)
        self._accounts: typing.Optional[AccountsClient] = None
        self._billing: typing.Optional[BillingClient] = None
        self._credits: typing.Optional[CreditsClient] = None
        self._checkout: typing.Optional[CheckoutClient] = None
        self._companies: typing.Optional[CompaniesClient] = None
        self._entitlements: typing.Optional[EntitlementsClient] = None
        self._plans: typing.Optional[PlansClient] = None
        self._components: typing.Optional[ComponentsClient] = None
        self._crm: typing.Optional[CrmClient] = None
        self._dataexports: typing.Optional[DataexportsClient] = None
        self._events: typing.Optional[EventsClient] = None
        self._features: typing.Optional[FeaturesClient] = None
        self._plangroups: typing.Optional[PlangroupsClient] = None
        self._accesstokens: typing.Optional[AccesstokensClient] = None
        self._webhooks: typing.Optional[WebhooksClient] = None

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

        Returns
        -------
        RawBaseSchematic
        """
        return self._raw_client

    def put_plan_audiences_plan_audience_id(
        self, plan_audience_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Parameters
        ----------
        plan_audience_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.put_plan_audiences_plan_audience_id(
            plan_audience_id="plan_audience_id",
        )
        """
        _response = self._raw_client.put_plan_audiences_plan_audience_id(
            plan_audience_id, request_options=request_options
        )
        return _response.data

    def delete_plan_audiences_plan_audience_id(
        self, plan_audience_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Parameters
        ----------
        plan_audience_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.delete_plan_audiences_plan_audience_id(
            plan_audience_id="plan_audience_id",
        )
        """
        _response = self._raw_client.delete_plan_audiences_plan_audience_id(
            plan_audience_id, request_options=request_options
        )
        return _response.data

    @property
    def accounts(self):
        if self._accounts is None:
            from .accounts.client import AccountsClient  # noqa: E402

            self._accounts = AccountsClient(client_wrapper=self._client_wrapper)
        return self._accounts

    @property
    def billing(self):
        if self._billing is None:
            from .billing.client import BillingClient  # noqa: E402

            self._billing = BillingClient(client_wrapper=self._client_wrapper)
        return self._billing

    @property
    def credits(self):
        if self._credits is None:
            from .credits.client import CreditsClient  # noqa: E402

            self._credits = CreditsClient(client_wrapper=self._client_wrapper)
        return self._credits

    @property
    def checkout(self):
        if self._checkout is None:
            from .checkout.client import CheckoutClient  # noqa: E402

            self._checkout = CheckoutClient(client_wrapper=self._client_wrapper)
        return self._checkout

    @property
    def companies(self):
        if self._companies is None:
            from .companies.client import CompaniesClient  # noqa: E402

            self._companies = CompaniesClient(client_wrapper=self._client_wrapper)
        return self._companies

    @property
    def entitlements(self):
        if self._entitlements is None:
            from .entitlements.client import EntitlementsClient  # noqa: E402

            self._entitlements = EntitlementsClient(client_wrapper=self._client_wrapper)
        return self._entitlements

    @property
    def plans(self):
        if self._plans is None:
            from .plans.client import PlansClient  # noqa: E402

            self._plans = PlansClient(client_wrapper=self._client_wrapper)
        return self._plans

    @property
    def components(self):
        if self._components is None:
            from .components.client import ComponentsClient  # noqa: E402

            self._components = ComponentsClient(client_wrapper=self._client_wrapper)
        return self._components

    @property
    def crm(self):
        if self._crm is None:
            from .crm.client import CrmClient  # noqa: E402

            self._crm = CrmClient(client_wrapper=self._client_wrapper)
        return self._crm

    @property
    def dataexports(self):
        if self._dataexports is None:
            from .dataexports.client import DataexportsClient  # noqa: E402

            self._dataexports = DataexportsClient(client_wrapper=self._client_wrapper)
        return self._dataexports

    @property
    def events(self):
        if self._events is None:
            from .events.client import EventsClient  # noqa: E402

            self._events = EventsClient(client_wrapper=self._client_wrapper)
        return self._events

    @property
    def features(self):
        if self._features is None:
            from .features.client import FeaturesClient  # noqa: E402

            self._features = FeaturesClient(client_wrapper=self._client_wrapper)
        return self._features

    @property
    def plangroups(self):
        if self._plangroups is None:
            from .plangroups.client import PlangroupsClient  # noqa: E402

            self._plangroups = PlangroupsClient(client_wrapper=self._client_wrapper)
        return self._plangroups

    @property
    def accesstokens(self):
        if self._accesstokens is None:
            from .accesstokens.client import AccesstokensClient  # noqa: E402

            self._accesstokens = AccesstokensClient(client_wrapper=self._client_wrapper)
        return self._accesstokens

    @property
    def webhooks(self):
        if self._webhooks is None:
            from .webhooks.client import WebhooksClient  # noqa: E402

            self._webhooks = WebhooksClient(client_wrapper=self._client_wrapper)
        return self._webhooks


class AsyncBaseSchematic:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : typing.Optional[str]
        The base url to use for requests from the client.

    environment : SchematicEnvironment
        The environment to use for requests from the client. from .environment import SchematicEnvironment



        Defaults to SchematicEnvironment.DEFAULT



    api_key : str
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.AsyncClient]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    Examples
    --------
    from schematic import AsyncSchematic

    client = AsyncSchematic(
        api_key="YOUR_API_KEY",
    )
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: SchematicEnvironment = SchematicEnvironment.DEFAULT,
        api_key: str,
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.AsyncClient] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        self._client_wrapper = AsyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            api_key=api_key,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
        )
        self._raw_client = AsyncRawBaseSchematic(client_wrapper=self._client_wrapper)
        self._accounts: typing.Optional[AsyncAccountsClient] = None
        self._billing: typing.Optional[AsyncBillingClient] = None
        self._credits: typing.Optional[AsyncCreditsClient] = None
        self._checkout: typing.Optional[AsyncCheckoutClient] = None
        self._companies: typing.Optional[AsyncCompaniesClient] = None
        self._entitlements: typing.Optional[AsyncEntitlementsClient] = None
        self._plans: typing.Optional[AsyncPlansClient] = None
        self._components: typing.Optional[AsyncComponentsClient] = None
        self._crm: typing.Optional[AsyncCrmClient] = None
        self._dataexports: typing.Optional[AsyncDataexportsClient] = None
        self._events: typing.Optional[AsyncEventsClient] = None
        self._features: typing.Optional[AsyncFeaturesClient] = None
        self._plangroups: typing.Optional[AsyncPlangroupsClient] = None
        self._accesstokens: typing.Optional[AsyncAccesstokensClient] = None
        self._webhooks: typing.Optional[AsyncWebhooksClient] = None

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

        Returns
        -------
        AsyncRawBaseSchematic
        """
        return self._raw_client

    async def put_plan_audiences_plan_audience_id(
        self, plan_audience_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Parameters
        ----------
        plan_audience_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.put_plan_audiences_plan_audience_id(
                plan_audience_id="plan_audience_id",
            )


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

    async def delete_plan_audiences_plan_audience_id(
        self, plan_audience_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Parameters
        ----------
        plan_audience_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.delete_plan_audiences_plan_audience_id(
                plan_audience_id="plan_audience_id",
            )


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

    @property
    def accounts(self):
        if self._accounts is None:
            from .accounts.client import AsyncAccountsClient  # noqa: E402

            self._accounts = AsyncAccountsClient(client_wrapper=self._client_wrapper)
        return self._accounts

    @property
    def billing(self):
        if self._billing is None:
            from .billing.client import AsyncBillingClient  # noqa: E402

            self._billing = AsyncBillingClient(client_wrapper=self._client_wrapper)
        return self._billing

    @property
    def credits(self):
        if self._credits is None:
            from .credits.client import AsyncCreditsClient  # noqa: E402

            self._credits = AsyncCreditsClient(client_wrapper=self._client_wrapper)
        return self._credits

    @property
    def checkout(self):
        if self._checkout is None:
            from .checkout.client import AsyncCheckoutClient  # noqa: E402

            self._checkout = AsyncCheckoutClient(client_wrapper=self._client_wrapper)
        return self._checkout

    @property
    def companies(self):
        if self._companies is None:
            from .companies.client import AsyncCompaniesClient  # noqa: E402

            self._companies = AsyncCompaniesClient(client_wrapper=self._client_wrapper)
        return self._companies

    @property
    def entitlements(self):
        if self._entitlements is None:
            from .entitlements.client import AsyncEntitlementsClient  # noqa: E402

            self._entitlements = AsyncEntitlementsClient(client_wrapper=self._client_wrapper)
        return self._entitlements

    @property
    def plans(self):
        if self._plans is None:
            from .plans.client import AsyncPlansClient  # noqa: E402

            self._plans = AsyncPlansClient(client_wrapper=self._client_wrapper)
        return self._plans

    @property
    def components(self):
        if self._components is None:
            from .components.client import AsyncComponentsClient  # noqa: E402

            self._components = AsyncComponentsClient(client_wrapper=self._client_wrapper)
        return self._components

    @property
    def crm(self):
        if self._crm is None:
            from .crm.client import AsyncCrmClient  # noqa: E402

            self._crm = AsyncCrmClient(client_wrapper=self._client_wrapper)
        return self._crm

    @property
    def dataexports(self):
        if self._dataexports is None:
            from .dataexports.client import AsyncDataexportsClient  # noqa: E402

            self._dataexports = AsyncDataexportsClient(client_wrapper=self._client_wrapper)
        return self._dataexports

    @property
    def events(self):
        if self._events is None:
            from .events.client import AsyncEventsClient  # noqa: E402

            self._events = AsyncEventsClient(client_wrapper=self._client_wrapper)
        return self._events

    @property
    def features(self):
        if self._features is None:
            from .features.client import AsyncFeaturesClient  # noqa: E402

            self._features = AsyncFeaturesClient(client_wrapper=self._client_wrapper)
        return self._features

    @property
    def plangroups(self):
        if self._plangroups is None:
            from .plangroups.client import AsyncPlangroupsClient  # noqa: E402

            self._plangroups = AsyncPlangroupsClient(client_wrapper=self._client_wrapper)
        return self._plangroups

    @property
    def accesstokens(self):
        if self._accesstokens is None:
            from .accesstokens.client import AsyncAccesstokensClient  # noqa: E402

            self._accesstokens = AsyncAccesstokensClient(client_wrapper=self._client_wrapper)
        return self._accesstokens

    @property
    def webhooks(self):
        if self._webhooks is None:
            from .webhooks.client import AsyncWebhooksClient  # noqa: E402

            self._webhooks = AsyncWebhooksClient(client_wrapper=self._client_wrapper)
        return self._webhooks


def _get_base_url(*, base_url: typing.Optional[str] = None, environment: SchematicEnvironment) -> str:
    if base_url is not None:
        return base_url
    elif environment is not None:
        return environment.value
    else:
        raise Exception("Please pass in either base_url or environment to construct the client")
