# 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.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.parse_error import ParsingError
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.bad_request_error import BadRequestError
from ..errors.internal_server_error import InternalServerError
from ..errors.service_unavailable_error import ServiceUnavailableError
from ..errors.unauthorized_error import UnauthorizedError
from ..money_out_types.types.authorize_payment_method import AuthorizePaymentMethod
from ..money_out_types.types.request_out_authorize_vendor_data import RequestOutAuthorizeVendorData
from ..types.account_id import AccountId
from ..types.bill_pay_out_data_request import BillPayOutDataRequest
from ..types.entrypointfield import Entrypointfield
from ..types.idempotency_key import IdempotencyKey
from ..types.payabli_api_response import PayabliApiResponse
from ..types.source import Source
from ..types.subdomain import Subdomain
from .types.add_payout_subscription_response import AddPayoutSubscriptionResponse
from .types.delete_payout_subscription_response import DeletePayoutSubscriptionResponse
from .types.get_payout_subscription_response import GetPayoutSubscriptionResponse
from .types.payout_payment_detail import PayoutPaymentDetail
from .types.payout_schedule_detail import PayoutScheduleDetail
from .types.payout_set_pause import PayoutSetPause
from .types.update_payout_subscription_response import UpdatePayoutSubscriptionResponse
from pydantic import ValidationError

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


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

    def create_payout_subscription(
        self,
        *,
        entry_point: Entrypointfield,
        payment_method: AuthorizePaymentMethod,
        vendor_data: RequestOutAuthorizeVendorData,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        subdomain: typing.Optional[Subdomain] = OMIT,
        account_id: typing.Optional[AccountId] = OMIT,
        source: typing.Optional[Source] = OMIT,
        set_pause: typing.Optional[PayoutSetPause] = OMIT,
        payment_details: typing.Optional[PayoutPaymentDetail] = OMIT,
        bill_data: typing.Optional[typing.Sequence[BillPayOutDataRequest]] = OMIT,
        schedule_details: typing.Optional[PayoutScheduleDetail] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AddPayoutSubscriptionResponse]:
        """
        Creates a payout subscription to automatically send payouts to a vendor on a recurring schedule. See [Manage payout subscriptions](/guides/pay-out-developer-payout-subscriptions-manage) for a step-by-step guide.

        Parameters
        ----------
        entry_point : Entrypointfield

        payment_method : AuthorizePaymentMethod
            Payment method for the payout subscription. Supports `ach`, `vcard`, and `check`. The `managed` method isn't supported for payout subscriptions.

        vendor_data : RequestOutAuthorizeVendorData
            Object identifying the vendor for this subscription. Only a `vendorId` or `vendorNumber` is needed to link to an existing vendor.

        idempotency_key : typing.Optional[IdempotencyKey]

        subdomain : typing.Optional[Subdomain]

        account_id : typing.Optional[AccountId]

        source : typing.Optional[Source]

        set_pause : typing.Optional[PayoutSetPause]

        payment_details : typing.Optional[PayoutPaymentDetail]
            Object describing details of the payout.

        bill_data : typing.Optional[typing.Sequence[BillPayOutDataRequest]]
            Array of bills associated with the payout subscription. If omitted and `doNotCreateBills` isn't set to `true`, the system creates a bill automatically.

        schedule_details : typing.Optional[PayoutScheduleDetail]
            Object describing the schedule for the payout subscription.

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

        Returns
        -------
        HttpResponse[AddPayoutSubscriptionResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            "PayoutSubscription",
            method="POST",
            json={
                "entryPoint": entry_point,
                "subdomain": subdomain,
                "accountId": account_id,
                "source": source,
                "setPause": set_pause,
                "paymentMethod": convert_and_respect_annotation_metadata(
                    object_=payment_method, annotation=AuthorizePaymentMethod, direction="write"
                ),
                "paymentDetails": convert_and_respect_annotation_metadata(
                    object_=payment_details, annotation=PayoutPaymentDetail, direction="write"
                ),
                "vendorData": convert_and_respect_annotation_metadata(
                    object_=vendor_data, annotation=RequestOutAuthorizeVendorData, direction="write"
                ),
                "billData": convert_and_respect_annotation_metadata(
                    object_=bill_data, annotation=typing.Sequence[BillPayOutDataRequest], direction="write"
                ),
                "scheduleDetails": convert_and_respect_annotation_metadata(
                    object_=schedule_details, annotation=PayoutScheduleDetail, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
                "idempotencyKey": str(idempotency_key) if idempotency_key is not None else None,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddPayoutSubscriptionResponse,
                    parse_obj_as(
                        type_=AddPayoutSubscriptionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        except ValidationError as e:
            raise ParsingError(
                status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
            )
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_payout_subscription(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[GetPayoutSubscriptionResponse]:
        """
        Retrieves a single payout subscription's details. See [Manage payout subscriptions](/guides/pay-out-developer-payout-subscriptions-manage) for more information.

        Parameters
        ----------
        id : int
            The payout subscription ID.

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

        Returns
        -------
        HttpResponse[GetPayoutSubscriptionResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"PayoutSubscription/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetPayoutSubscriptionResponse,
                    parse_obj_as(
                        type_=GetPayoutSubscriptionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        except ValidationError as e:
            raise ParsingError(
                status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
            )
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def update_payout_subscription(
        self,
        id: int,
        *,
        set_pause: typing.Optional[PayoutSetPause] = OMIT,
        payment_details: typing.Optional[PayoutPaymentDetail] = OMIT,
        payment_method: typing.Optional[AuthorizePaymentMethod] = OMIT,
        schedule_details: typing.Optional[PayoutScheduleDetail] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[UpdatePayoutSubscriptionResponse]:
        """
        Updates a payout subscription's details. See [Manage payout subscriptions](/guides/pay-out-developer-payout-subscriptions-manage) for more information.

        Parameters
        ----------
        id : int
            The payout subscription ID.

        set_pause : typing.Optional[PayoutSetPause]

        payment_details : typing.Optional[PayoutPaymentDetail]
            Object describing details of the payout.

        payment_method : typing.Optional[AuthorizePaymentMethod]

        schedule_details : typing.Optional[PayoutScheduleDetail]
            Object describing the schedule for the payout subscription.

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

        Returns
        -------
        HttpResponse[UpdatePayoutSubscriptionResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"PayoutSubscription/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "setPause": set_pause,
                "paymentDetails": convert_and_respect_annotation_metadata(
                    object_=payment_details, annotation=PayoutPaymentDetail, direction="write"
                ),
                "paymentMethod": convert_and_respect_annotation_metadata(
                    object_=payment_method, annotation=AuthorizePaymentMethod, direction="write"
                ),
                "scheduleDetails": convert_and_respect_annotation_metadata(
                    object_=schedule_details, annotation=PayoutScheduleDetail, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UpdatePayoutSubscriptionResponse,
                    parse_obj_as(
                        type_=UpdatePayoutSubscriptionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        except ValidationError as e:
            raise ParsingError(
                status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
            )
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete_payout_subscription(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[DeletePayoutSubscriptionResponse]:
        """
        Deletes a payout subscription and prevents future payouts. See [Manage payout subscriptions](/guides/pay-out-developer-payout-subscriptions-manage) for more information.

        Parameters
        ----------
        id : int
            The payout subscription ID.

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

        Returns
        -------
        HttpResponse[DeletePayoutSubscriptionResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"PayoutSubscription/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeletePayoutSubscriptionResponse,
                    parse_obj_as(
                        type_=DeletePayoutSubscriptionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        except ValidationError as e:
            raise ParsingError(
                status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
            )
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawPayoutSubscriptionClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def create_payout_subscription(
        self,
        *,
        entry_point: Entrypointfield,
        payment_method: AuthorizePaymentMethod,
        vendor_data: RequestOutAuthorizeVendorData,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        subdomain: typing.Optional[Subdomain] = OMIT,
        account_id: typing.Optional[AccountId] = OMIT,
        source: typing.Optional[Source] = OMIT,
        set_pause: typing.Optional[PayoutSetPause] = OMIT,
        payment_details: typing.Optional[PayoutPaymentDetail] = OMIT,
        bill_data: typing.Optional[typing.Sequence[BillPayOutDataRequest]] = OMIT,
        schedule_details: typing.Optional[PayoutScheduleDetail] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AddPayoutSubscriptionResponse]:
        """
        Creates a payout subscription to automatically send payouts to a vendor on a recurring schedule. See [Manage payout subscriptions](/guides/pay-out-developer-payout-subscriptions-manage) for a step-by-step guide.

        Parameters
        ----------
        entry_point : Entrypointfield

        payment_method : AuthorizePaymentMethod
            Payment method for the payout subscription. Supports `ach`, `vcard`, and `check`. The `managed` method isn't supported for payout subscriptions.

        vendor_data : RequestOutAuthorizeVendorData
            Object identifying the vendor for this subscription. Only a `vendorId` or `vendorNumber` is needed to link to an existing vendor.

        idempotency_key : typing.Optional[IdempotencyKey]

        subdomain : typing.Optional[Subdomain]

        account_id : typing.Optional[AccountId]

        source : typing.Optional[Source]

        set_pause : typing.Optional[PayoutSetPause]

        payment_details : typing.Optional[PayoutPaymentDetail]
            Object describing details of the payout.

        bill_data : typing.Optional[typing.Sequence[BillPayOutDataRequest]]
            Array of bills associated with the payout subscription. If omitted and `doNotCreateBills` isn't set to `true`, the system creates a bill automatically.

        schedule_details : typing.Optional[PayoutScheduleDetail]
            Object describing the schedule for the payout subscription.

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

        Returns
        -------
        AsyncHttpResponse[AddPayoutSubscriptionResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            "PayoutSubscription",
            method="POST",
            json={
                "entryPoint": entry_point,
                "subdomain": subdomain,
                "accountId": account_id,
                "source": source,
                "setPause": set_pause,
                "paymentMethod": convert_and_respect_annotation_metadata(
                    object_=payment_method, annotation=AuthorizePaymentMethod, direction="write"
                ),
                "paymentDetails": convert_and_respect_annotation_metadata(
                    object_=payment_details, annotation=PayoutPaymentDetail, direction="write"
                ),
                "vendorData": convert_and_respect_annotation_metadata(
                    object_=vendor_data, annotation=RequestOutAuthorizeVendorData, direction="write"
                ),
                "billData": convert_and_respect_annotation_metadata(
                    object_=bill_data, annotation=typing.Sequence[BillPayOutDataRequest], direction="write"
                ),
                "scheduleDetails": convert_and_respect_annotation_metadata(
                    object_=schedule_details, annotation=PayoutScheduleDetail, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
                "idempotencyKey": str(idempotency_key) if idempotency_key is not None else None,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddPayoutSubscriptionResponse,
                    parse_obj_as(
                        type_=AddPayoutSubscriptionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        except ValidationError as e:
            raise ParsingError(
                status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
            )
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_payout_subscription(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[GetPayoutSubscriptionResponse]:
        """
        Retrieves a single payout subscription's details. See [Manage payout subscriptions](/guides/pay-out-developer-payout-subscriptions-manage) for more information.

        Parameters
        ----------
        id : int
            The payout subscription ID.

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

        Returns
        -------
        AsyncHttpResponse[GetPayoutSubscriptionResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"PayoutSubscription/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetPayoutSubscriptionResponse,
                    parse_obj_as(
                        type_=GetPayoutSubscriptionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        except ValidationError as e:
            raise ParsingError(
                status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
            )
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def update_payout_subscription(
        self,
        id: int,
        *,
        set_pause: typing.Optional[PayoutSetPause] = OMIT,
        payment_details: typing.Optional[PayoutPaymentDetail] = OMIT,
        payment_method: typing.Optional[AuthorizePaymentMethod] = OMIT,
        schedule_details: typing.Optional[PayoutScheduleDetail] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[UpdatePayoutSubscriptionResponse]:
        """
        Updates a payout subscription's details. See [Manage payout subscriptions](/guides/pay-out-developer-payout-subscriptions-manage) for more information.

        Parameters
        ----------
        id : int
            The payout subscription ID.

        set_pause : typing.Optional[PayoutSetPause]

        payment_details : typing.Optional[PayoutPaymentDetail]
            Object describing details of the payout.

        payment_method : typing.Optional[AuthorizePaymentMethod]

        schedule_details : typing.Optional[PayoutScheduleDetail]
            Object describing the schedule for the payout subscription.

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

        Returns
        -------
        AsyncHttpResponse[UpdatePayoutSubscriptionResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"PayoutSubscription/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "setPause": set_pause,
                "paymentDetails": convert_and_respect_annotation_metadata(
                    object_=payment_details, annotation=PayoutPaymentDetail, direction="write"
                ),
                "paymentMethod": convert_and_respect_annotation_metadata(
                    object_=payment_method, annotation=AuthorizePaymentMethod, direction="write"
                ),
                "scheduleDetails": convert_and_respect_annotation_metadata(
                    object_=schedule_details, annotation=PayoutScheduleDetail, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UpdatePayoutSubscriptionResponse,
                    parse_obj_as(
                        type_=UpdatePayoutSubscriptionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        except ValidationError as e:
            raise ParsingError(
                status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
            )
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete_payout_subscription(
        self, id: int, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[DeletePayoutSubscriptionResponse]:
        """
        Deletes a payout subscription and prevents future payouts. See [Manage payout subscriptions](/guides/pay-out-developer-payout-subscriptions-manage) for more information.

        Parameters
        ----------
        id : int
            The payout subscription ID.

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

        Returns
        -------
        AsyncHttpResponse[DeletePayoutSubscriptionResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"PayoutSubscription/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeletePayoutSubscriptionResponse,
                    parse_obj_as(
                        type_=DeletePayoutSubscriptionResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 503:
                raise ServiceUnavailableError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        PayabliApiResponse,
                        parse_obj_as(
                            type_=PayabliApiResponse,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        except ValidationError as e:
            raise ParsingError(
                status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
            )
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
