# 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 ..types.update_add_on_request_body import UpdateAddOnRequestBody
from ..types.update_pay_in_advance_request_body import UpdatePayInAdvanceRequestBody
from .raw_client import AsyncRawCheckoutClient, RawCheckoutClient
from .types.checkout_internal_response import CheckoutInternalResponse
from .types.get_checkout_data_response import GetCheckoutDataResponse
from .types.preview_checkout_internal_response import PreviewCheckoutInternalResponse
from .types.update_customer_subscription_trial_end_response import UpdateCustomerSubscriptionTrialEndResponse

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


class CheckoutClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCheckoutClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCheckoutClient
        """
        return self._raw_client

    def internal(
        self,
        *,
        add_on_ids: typing.Sequence[UpdateAddOnRequestBody],
        company_id: str,
        new_plan_id: str,
        new_price_id: str,
        pay_in_advance: typing.Sequence[UpdatePayInAdvanceRequestBody],
        coupon_external_id: typing.Optional[str] = OMIT,
        payment_method_id: typing.Optional[str] = OMIT,
        promo_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CheckoutInternalResponse:
        """
        Parameters
        ----------
        add_on_ids : typing.Sequence[UpdateAddOnRequestBody]

        company_id : str

        new_plan_id : str

        new_price_id : str

        pay_in_advance : typing.Sequence[UpdatePayInAdvanceRequestBody]

        coupon_external_id : typing.Optional[str]

        payment_method_id : typing.Optional[str]

        promo_code : typing.Optional[str]

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

        Returns
        -------
        CheckoutInternalResponse
            Created

        Examples
        --------
        from schematic import (
            Schematic,
            UpdateAddOnRequestBody,
            UpdatePayInAdvanceRequestBody,
        )

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.checkout.internal(
            add_on_ids=[
                UpdateAddOnRequestBody(
                    add_on_id="add_on_id",
                    price_id="price_id",
                )
            ],
            company_id="company_id",
            new_plan_id="new_plan_id",
            new_price_id="new_price_id",
            pay_in_advance=[
                UpdatePayInAdvanceRequestBody(
                    price_id="price_id",
                    quantity=1,
                )
            ],
        )
        """
        _response = self._raw_client.internal(
            add_on_ids=add_on_ids,
            company_id=company_id,
            new_plan_id=new_plan_id,
            new_price_id=new_price_id,
            pay_in_advance=pay_in_advance,
            coupon_external_id=coupon_external_id,
            payment_method_id=payment_method_id,
            promo_code=promo_code,
            request_options=request_options,
        )
        return _response.data

    def get_checkout_data(
        self,
        *,
        company_id: str,
        selected_plan_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetCheckoutDataResponse:
        """
        Parameters
        ----------
        company_id : str

        selected_plan_id : typing.Optional[str]

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

        Returns
        -------
        GetCheckoutDataResponse
            OK

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

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.checkout.get_checkout_data(
            company_id="company_id",
        )
        """
        _response = self._raw_client.get_checkout_data(
            company_id=company_id, selected_plan_id=selected_plan_id, request_options=request_options
        )
        return _response.data

    def preview_checkout_internal(
        self,
        *,
        add_on_ids: typing.Sequence[UpdateAddOnRequestBody],
        company_id: str,
        new_plan_id: str,
        new_price_id: str,
        pay_in_advance: typing.Sequence[UpdatePayInAdvanceRequestBody],
        coupon_external_id: typing.Optional[str] = OMIT,
        payment_method_id: typing.Optional[str] = OMIT,
        promo_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PreviewCheckoutInternalResponse:
        """
        Parameters
        ----------
        add_on_ids : typing.Sequence[UpdateAddOnRequestBody]

        company_id : str

        new_plan_id : str

        new_price_id : str

        pay_in_advance : typing.Sequence[UpdatePayInAdvanceRequestBody]

        coupon_external_id : typing.Optional[str]

        payment_method_id : typing.Optional[str]

        promo_code : typing.Optional[str]

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

        Returns
        -------
        PreviewCheckoutInternalResponse
            OK

        Examples
        --------
        from schematic import (
            Schematic,
            UpdateAddOnRequestBody,
            UpdatePayInAdvanceRequestBody,
        )

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.checkout.preview_checkout_internal(
            add_on_ids=[
                UpdateAddOnRequestBody(
                    add_on_id="add_on_id",
                    price_id="price_id",
                )
            ],
            company_id="company_id",
            new_plan_id="new_plan_id",
            new_price_id="new_price_id",
            pay_in_advance=[
                UpdatePayInAdvanceRequestBody(
                    price_id="price_id",
                    quantity=1,
                )
            ],
        )
        """
        _response = self._raw_client.preview_checkout_internal(
            add_on_ids=add_on_ids,
            company_id=company_id,
            new_plan_id=new_plan_id,
            new_price_id=new_price_id,
            pay_in_advance=pay_in_advance,
            coupon_external_id=coupon_external_id,
            payment_method_id=payment_method_id,
            promo_code=promo_code,
            request_options=request_options,
        )
        return _response.data

    def update_customer_subscription_trial_end(
        self,
        subscription_id: str,
        *,
        trial_end: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateCustomerSubscriptionTrialEndResponse:
        """
        Parameters
        ----------
        subscription_id : str
            subscription_id

        trial_end : typing.Optional[dt.datetime]

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

        Returns
        -------
        UpdateCustomerSubscriptionTrialEndResponse
            OK

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

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.checkout.update_customer_subscription_trial_end(
            subscription_id="subscription_id",
        )
        """
        _response = self._raw_client.update_customer_subscription_trial_end(
            subscription_id, trial_end=trial_end, request_options=request_options
        )
        return _response.data


class AsyncCheckoutClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCheckoutClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCheckoutClient
        """
        return self._raw_client

    async def internal(
        self,
        *,
        add_on_ids: typing.Sequence[UpdateAddOnRequestBody],
        company_id: str,
        new_plan_id: str,
        new_price_id: str,
        pay_in_advance: typing.Sequence[UpdatePayInAdvanceRequestBody],
        coupon_external_id: typing.Optional[str] = OMIT,
        payment_method_id: typing.Optional[str] = OMIT,
        promo_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CheckoutInternalResponse:
        """
        Parameters
        ----------
        add_on_ids : typing.Sequence[UpdateAddOnRequestBody]

        company_id : str

        new_plan_id : str

        new_price_id : str

        pay_in_advance : typing.Sequence[UpdatePayInAdvanceRequestBody]

        coupon_external_id : typing.Optional[str]

        payment_method_id : typing.Optional[str]

        promo_code : typing.Optional[str]

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

        Returns
        -------
        CheckoutInternalResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import (
            AsyncSchematic,
            UpdateAddOnRequestBody,
            UpdatePayInAdvanceRequestBody,
        )

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.checkout.internal(
                add_on_ids=[
                    UpdateAddOnRequestBody(
                        add_on_id="add_on_id",
                        price_id="price_id",
                    )
                ],
                company_id="company_id",
                new_plan_id="new_plan_id",
                new_price_id="new_price_id",
                pay_in_advance=[
                    UpdatePayInAdvanceRequestBody(
                        price_id="price_id",
                        quantity=1,
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.internal(
            add_on_ids=add_on_ids,
            company_id=company_id,
            new_plan_id=new_plan_id,
            new_price_id=new_price_id,
            pay_in_advance=pay_in_advance,
            coupon_external_id=coupon_external_id,
            payment_method_id=payment_method_id,
            promo_code=promo_code,
            request_options=request_options,
        )
        return _response.data

    async def get_checkout_data(
        self,
        *,
        company_id: str,
        selected_plan_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetCheckoutDataResponse:
        """
        Parameters
        ----------
        company_id : str

        selected_plan_id : typing.Optional[str]

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

        Returns
        -------
        GetCheckoutDataResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.checkout.get_checkout_data(
                company_id="company_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_checkout_data(
            company_id=company_id, selected_plan_id=selected_plan_id, request_options=request_options
        )
        return _response.data

    async def preview_checkout_internal(
        self,
        *,
        add_on_ids: typing.Sequence[UpdateAddOnRequestBody],
        company_id: str,
        new_plan_id: str,
        new_price_id: str,
        pay_in_advance: typing.Sequence[UpdatePayInAdvanceRequestBody],
        coupon_external_id: typing.Optional[str] = OMIT,
        payment_method_id: typing.Optional[str] = OMIT,
        promo_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PreviewCheckoutInternalResponse:
        """
        Parameters
        ----------
        add_on_ids : typing.Sequence[UpdateAddOnRequestBody]

        company_id : str

        new_plan_id : str

        new_price_id : str

        pay_in_advance : typing.Sequence[UpdatePayInAdvanceRequestBody]

        coupon_external_id : typing.Optional[str]

        payment_method_id : typing.Optional[str]

        promo_code : typing.Optional[str]

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

        Returns
        -------
        PreviewCheckoutInternalResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import (
            AsyncSchematic,
            UpdateAddOnRequestBody,
            UpdatePayInAdvanceRequestBody,
        )

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.checkout.preview_checkout_internal(
                add_on_ids=[
                    UpdateAddOnRequestBody(
                        add_on_id="add_on_id",
                        price_id="price_id",
                    )
                ],
                company_id="company_id",
                new_plan_id="new_plan_id",
                new_price_id="new_price_id",
                pay_in_advance=[
                    UpdatePayInAdvanceRequestBody(
                        price_id="price_id",
                        quantity=1,
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.preview_checkout_internal(
            add_on_ids=add_on_ids,
            company_id=company_id,
            new_plan_id=new_plan_id,
            new_price_id=new_price_id,
            pay_in_advance=pay_in_advance,
            coupon_external_id=coupon_external_id,
            payment_method_id=payment_method_id,
            promo_code=promo_code,
            request_options=request_options,
        )
        return _response.data

    async def update_customer_subscription_trial_end(
        self,
        subscription_id: str,
        *,
        trial_end: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateCustomerSubscriptionTrialEndResponse:
        """
        Parameters
        ----------
        subscription_id : str
            subscription_id

        trial_end : typing.Optional[dt.datetime]

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

        Returns
        -------
        UpdateCustomerSubscriptionTrialEndResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.checkout.update_customer_subscription_trial_end(
                subscription_id="subscription_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_customer_subscription_trial_end(
            subscription_id, trial_end=trial_end, request_options=request_options
        )
        return _response.data
