# 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.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 ..types.add_payment_method_domain_api_response import AddPaymentMethodDomainApiResponse
from ..types.domain_name import DomainName
from ..types.entity_id import EntityId
from ..types.entity_type import EntityType
from ..types.payabli_api_response import PayabliApiResponse
from ..types.payment_method_domain_api_response import PaymentMethodDomainApiResponse
from ..types.payment_method_domain_general_response import PaymentMethodDomainGeneralResponse
from .types.add_payment_method_domain_request_apple_pay import AddPaymentMethodDomainRequestApplePay
from .types.add_payment_method_domain_request_google_pay import AddPaymentMethodDomainRequestGooglePay
from .types.delete_payment_method_domain_response import DeletePaymentMethodDomainResponse
from .types.list_payment_method_domains_response import ListPaymentMethodDomainsResponse
from .types.update_payment_method_domain_request_wallet import UpdatePaymentMethodDomainRequestWallet

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


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

    def add_payment_method_domain(
        self,
        *,
        apple_pay: typing.Optional[AddPaymentMethodDomainRequestApplePay] = OMIT,
        google_pay: typing.Optional[AddPaymentMethodDomainRequestGooglePay] = OMIT,
        domain_name: typing.Optional[DomainName] = OMIT,
        entity_id: typing.Optional[EntityId] = OMIT,
        entity_type: typing.Optional[EntityType] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AddPaymentMethodDomainApiResponse]:
        """
        Add a payment method domain to an organization or paypoint.

        Parameters
        ----------
        apple_pay : typing.Optional[AddPaymentMethodDomainRequestApplePay]
            Apple Pay configuration information.

        google_pay : typing.Optional[AddPaymentMethodDomainRequestGooglePay]
            Google Pay configuration information.

        domain_name : typing.Optional[DomainName]

        entity_id : typing.Optional[EntityId]

        entity_type : typing.Optional[EntityType]

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

        Returns
        -------
        HttpResponse[AddPaymentMethodDomainApiResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            "PaymentMethodDomain",
            method="POST",
            json={
                "applePay": convert_and_respect_annotation_metadata(
                    object_=apple_pay, annotation=AddPaymentMethodDomainRequestApplePay, direction="write"
                ),
                "googlePay": convert_and_respect_annotation_metadata(
                    object_=google_pay, annotation=AddPaymentMethodDomainRequestGooglePay, direction="write"
                ),
                "domainName": domain_name,
                "entityId": entity_id,
                "entityType": entity_type,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddPaymentMethodDomainApiResponse,
                    parse_obj_as(
                        type_=AddPaymentMethodDomainApiResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def cascade_payment_method_domain(
        self, domain_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[PaymentMethodDomainGeneralResponse]:
        """
        Cascades a payment method domain to all child entities. All paypoints and suborganization under this parent will inherit this domain and its settings.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

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

        Returns
        -------
        HttpResponse[PaymentMethodDomainGeneralResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}/cascade",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PaymentMethodDomainGeneralResponse,
                    parse_obj_as(
                        type_=PaymentMethodDomainGeneralResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete_payment_method_domain(
        self, domain_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[DeletePaymentMethodDomainResponse]:
        """
        Delete a payment method domain. You can't delete an inherited domain, you must delete a domain at the organization level.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

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

        Returns
        -------
        HttpResponse[DeletePaymentMethodDomainResponse]
            Success response for a deleted payment method domain.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeletePaymentMethodDomainResponse,
                    parse_obj_as(
                        type_=DeletePaymentMethodDomainResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_payment_method_domain(
        self, domain_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[PaymentMethodDomainApiResponse]:
        """
        Get the details for a payment method domain.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

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

        Returns
        -------
        HttpResponse[PaymentMethodDomainApiResponse]
            Success response that includes a payment method domain's details.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PaymentMethodDomainApiResponse,
                    parse_obj_as(
                        type_=PaymentMethodDomainApiResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def list_payment_method_domains(
        self,
        *,
        entity_id: typing.Optional[int] = None,
        entity_type: typing.Optional[str] = None,
        from_record: typing.Optional[int] = None,
        limit_record: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ListPaymentMethodDomainsResponse]:
        """
        Get a list of payment method domains that belong to a PSP, organization, or paypoint.

        Parameters
        ----------
        entity_id : typing.Optional[int]
            Identifier for the organization or paypoint.
            - For organization, provide the organization ID - For paypoint, provide the paypoint ID

        entity_type : typing.Optional[str]
            The type of entity. Valid values:
              - organization
              - paypoint
              - psp

        from_record : typing.Optional[int]
            Number of records to skip. Defaults to `0`.

        limit_record : typing.Optional[int]
            Max number of records for query response. Defaults to `20`.

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

        Returns
        -------
        HttpResponse[ListPaymentMethodDomainsResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            "PaymentMethodDomain/list",
            method="GET",
            params={
                "entityId": entity_id,
                "entityType": entity_type,
                "fromRecord": from_record,
                "limitRecord": limit_record,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ListPaymentMethodDomainsResponse,
                    parse_obj_as(
                        type_=ListPaymentMethodDomainsResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def update_payment_method_domain(
        self,
        domain_id: str,
        *,
        apple_pay: typing.Optional[UpdatePaymentMethodDomainRequestWallet] = OMIT,
        google_pay: typing.Optional[UpdatePaymentMethodDomainRequestWallet] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[PaymentMethodDomainGeneralResponse]:
        """
        Update a payment method domain's configuration values.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

        apple_pay : typing.Optional[UpdatePaymentMethodDomainRequestWallet]

        google_pay : typing.Optional[UpdatePaymentMethodDomainRequestWallet]

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

        Returns
        -------
        HttpResponse[PaymentMethodDomainGeneralResponse]
            Success response for configuration update.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}",
            method="PATCH",
            json={
                "applePay": convert_and_respect_annotation_metadata(
                    object_=apple_pay, annotation=UpdatePaymentMethodDomainRequestWallet, direction="write"
                ),
                "googlePay": convert_and_respect_annotation_metadata(
                    object_=google_pay, annotation=UpdatePaymentMethodDomainRequestWallet, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PaymentMethodDomainGeneralResponse,
                    parse_obj_as(
                        type_=PaymentMethodDomainGeneralResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def verify_payment_method_domain(
        self, domain_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[PaymentMethodDomainGeneralResponse]:
        """
        Verify a new payment method domain. If verification is successful, Apple Pay is automatically activated for the domain.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

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

        Returns
        -------
        HttpResponse[PaymentMethodDomainGeneralResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}/verify",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PaymentMethodDomainGeneralResponse,
                    parse_obj_as(
                        type_=PaymentMethodDomainGeneralResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


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

    async def add_payment_method_domain(
        self,
        *,
        apple_pay: typing.Optional[AddPaymentMethodDomainRequestApplePay] = OMIT,
        google_pay: typing.Optional[AddPaymentMethodDomainRequestGooglePay] = OMIT,
        domain_name: typing.Optional[DomainName] = OMIT,
        entity_id: typing.Optional[EntityId] = OMIT,
        entity_type: typing.Optional[EntityType] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AddPaymentMethodDomainApiResponse]:
        """
        Add a payment method domain to an organization or paypoint.

        Parameters
        ----------
        apple_pay : typing.Optional[AddPaymentMethodDomainRequestApplePay]
            Apple Pay configuration information.

        google_pay : typing.Optional[AddPaymentMethodDomainRequestGooglePay]
            Google Pay configuration information.

        domain_name : typing.Optional[DomainName]

        entity_id : typing.Optional[EntityId]

        entity_type : typing.Optional[EntityType]

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

        Returns
        -------
        AsyncHttpResponse[AddPaymentMethodDomainApiResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            "PaymentMethodDomain",
            method="POST",
            json={
                "applePay": convert_and_respect_annotation_metadata(
                    object_=apple_pay, annotation=AddPaymentMethodDomainRequestApplePay, direction="write"
                ),
                "googlePay": convert_and_respect_annotation_metadata(
                    object_=google_pay, annotation=AddPaymentMethodDomainRequestGooglePay, direction="write"
                ),
                "domainName": domain_name,
                "entityId": entity_id,
                "entityType": entity_type,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddPaymentMethodDomainApiResponse,
                    parse_obj_as(
                        type_=AddPaymentMethodDomainApiResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def cascade_payment_method_domain(
        self, domain_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[PaymentMethodDomainGeneralResponse]:
        """
        Cascades a payment method domain to all child entities. All paypoints and suborganization under this parent will inherit this domain and its settings.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

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

        Returns
        -------
        AsyncHttpResponse[PaymentMethodDomainGeneralResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}/cascade",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PaymentMethodDomainGeneralResponse,
                    parse_obj_as(
                        type_=PaymentMethodDomainGeneralResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete_payment_method_domain(
        self, domain_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[DeletePaymentMethodDomainResponse]:
        """
        Delete a payment method domain. You can't delete an inherited domain, you must delete a domain at the organization level.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

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

        Returns
        -------
        AsyncHttpResponse[DeletePaymentMethodDomainResponse]
            Success response for a deleted payment method domain.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeletePaymentMethodDomainResponse,
                    parse_obj_as(
                        type_=DeletePaymentMethodDomainResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_payment_method_domain(
        self, domain_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[PaymentMethodDomainApiResponse]:
        """
        Get the details for a payment method domain.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

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

        Returns
        -------
        AsyncHttpResponse[PaymentMethodDomainApiResponse]
            Success response that includes a payment method domain's details.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PaymentMethodDomainApiResponse,
                    parse_obj_as(
                        type_=PaymentMethodDomainApiResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def list_payment_method_domains(
        self,
        *,
        entity_id: typing.Optional[int] = None,
        entity_type: typing.Optional[str] = None,
        from_record: typing.Optional[int] = None,
        limit_record: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ListPaymentMethodDomainsResponse]:
        """
        Get a list of payment method domains that belong to a PSP, organization, or paypoint.

        Parameters
        ----------
        entity_id : typing.Optional[int]
            Identifier for the organization or paypoint.
            - For organization, provide the organization ID - For paypoint, provide the paypoint ID

        entity_type : typing.Optional[str]
            The type of entity. Valid values:
              - organization
              - paypoint
              - psp

        from_record : typing.Optional[int]
            Number of records to skip. Defaults to `0`.

        limit_record : typing.Optional[int]
            Max number of records for query response. Defaults to `20`.

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

        Returns
        -------
        AsyncHttpResponse[ListPaymentMethodDomainsResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            "PaymentMethodDomain/list",
            method="GET",
            params={
                "entityId": entity_id,
                "entityType": entity_type,
                "fromRecord": from_record,
                "limitRecord": limit_record,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ListPaymentMethodDomainsResponse,
                    parse_obj_as(
                        type_=ListPaymentMethodDomainsResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def update_payment_method_domain(
        self,
        domain_id: str,
        *,
        apple_pay: typing.Optional[UpdatePaymentMethodDomainRequestWallet] = OMIT,
        google_pay: typing.Optional[UpdatePaymentMethodDomainRequestWallet] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[PaymentMethodDomainGeneralResponse]:
        """
        Update a payment method domain's configuration values.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

        apple_pay : typing.Optional[UpdatePaymentMethodDomainRequestWallet]

        google_pay : typing.Optional[UpdatePaymentMethodDomainRequestWallet]

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

        Returns
        -------
        AsyncHttpResponse[PaymentMethodDomainGeneralResponse]
            Success response for configuration update.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}",
            method="PATCH",
            json={
                "applePay": convert_and_respect_annotation_metadata(
                    object_=apple_pay, annotation=UpdatePaymentMethodDomainRequestWallet, direction="write"
                ),
                "googlePay": convert_and_respect_annotation_metadata(
                    object_=google_pay, annotation=UpdatePaymentMethodDomainRequestWallet, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PaymentMethodDomainGeneralResponse,
                    parse_obj_as(
                        type_=PaymentMethodDomainGeneralResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def verify_payment_method_domain(
        self, domain_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[PaymentMethodDomainGeneralResponse]:
        """
        Verify a new payment method domain. If verification is successful, Apple Pay is automatically activated for the domain.

        Parameters
        ----------
        domain_id : str
            The payment method domain's ID in Payabli.

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

        Returns
        -------
        AsyncHttpResponse[PaymentMethodDomainGeneralResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"PaymentMethodDomain/{jsonable_encoder(domain_id)}/verify",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PaymentMethodDomainGeneralResponse,
                    parse_obj_as(
                        type_=PaymentMethodDomainGeneralResponse,  # 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.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[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)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
