"""visaacceptancemergedspec.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: D410, E501, E101, D206
from apimatic_core.authentication.multiple.and_auth_group import (
    And,
)
from apimatic_core.authentication.multiple.single_auth import (
    Single,
)
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter

from visaacceptancemergedspec.api_helper import (
    APIHelper,
)
from visaacceptancemergedspec.apis.base_api import (
    BaseApi,
)
from visaacceptancemergedspec.configuration import (
    Server,
)
from visaacceptancemergedspec.exceptions.pts_v_2_create_billing_agreement_post_400_response_1_exception import (  # noqa: E501
    PtsV2CreateBillingAgreementPost400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_create_billing_agreement_post_502_response_1_exception import (  # noqa: E501
    PtsV2CreateBillingAgreementPost502Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_credits_post_400_response_21_exception import (  # noqa: E501
    PtsV2CreditsPost400Response21Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_credits_post_502_response_21_exception import (  # noqa: E501
    PtsV2CreditsPost502Response21Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_modify_billing_agreement_post_400_response_1_exception import (  # noqa: E501
    PtsV2ModifyBillingAgreementPost400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_modify_billing_agreement_post_502_response_1_exception import (  # noqa: E501
    PtsV2ModifyBillingAgreementPost502Response1Exception,
)
from visaacceptancemergedspec.http.http_method_enum import (
    HttpMethodEnum,
)
from visaacceptancemergedspec.models.pts_v_2_create_billing_agreement_post_201_response import (  # noqa: E501
    PtsV2CreateBillingAgreementPost201Response,
)
from visaacceptancemergedspec.models.pts_v_2_credits_post_201_response_1 import (
    PtsV2CreditsPost201Response1,
)
from visaacceptancemergedspec.models.pts_v_2_modify_billing_agreement_post_201_response import (  # noqa: E501
    PtsV2ModifyBillingAgreementPost201Response,
)


class BillingAgreementsApi(BaseApi):
    """A Controller to access Endpoints in the visaacceptancemergedspec API."""

    def __init__(self, config):
        """Initialize BillingAgreementsApi object."""
        super(BillingAgreementsApi, self).__init__(config)

    def billing_agreements_registration(self,
                                        body):
        """Perform a POST request to /pts/v2/billing-agreements.

        #### Standing Instruction:
        Standing Instruction with or without Token. Transaction amount in case First
        payment is coming along with registration. Only 2 decimal places allowed
        #### Create Mandate:
        You can create a mandate through the direct debit mandate flow.
        Possible create mandate status values:
          - Pending—the create mandate request was successfully processed.
          - Failed—the create mandate request was not accepted.
        #### Import Mandate:
        In the Bacs scheme, a mandate is created with a status of active. Direct
        debit collections can be made against it immediately.
        You can import a mandate to the Visa Acceptance database when:
          - You have existing customers with signed, active mandates
          - You manage mandates outside of Visa Acceptance.
        When you import an existing mandate to the Visa Acceptance database, provide
        a unique value for the mandate ID or the request results in an error.
        If an import mandate request is not accepted, the import mandate status value
        is failed.

        Args:
            body (CreateBillingAgreement): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/billing-agreements")
            .http_method(HttpMethodEnum.POST)
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PtsV2CreateBillingAgreementPost201Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2CreateBillingAgreementPost400Response1Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2CreateBillingAgreementPost502Response1Exception),
        ).execute()

    def billing_agreements_de_registration(self,
                                           id,
                                           body):
        """Perform a PATCH request to /pts/v2/billing-agreements/{id}.

        #### Standing Instruction:
        Standing Instruction with or without Token.
        #### Revoke Mandate:
        When you revoke a mandate, any pending direct debits linked to that mandate
        are canceled. No notifications are sent.
        When you revoke a mandate with no pending direct debits, the Bacs scheme or
        customer’s bank notify you of any subsequent direct debit events.
        When you revoke a mandate, you cannot send a direct debit request using the
        mandate ID. Customer payments cannot be made against a revoked mandate.
        You can revoke a mandate when the customer:
          - Requests that you revoke the mandate.
          - Closes their account with you.
        Possible revoke mandate status values -
          - Revoked—the revoke mandate request was successfully processed.
          - Failed—the revoke mandate request was not accepted.
        #### Update Mandate:
        In most cases, the account details of an existing mandate cannot be updated
        in the Bacs schema,
        except by creating a new mandate. However, some very limited customer
        information, like name and address,
        can be updated to the mandate without needing to revoke it first
        #### Mandate Status:
        After the customer signs the mandate, request that the mandate status service
        verify the mandate status.
        Possible mandate status values:
          - Active—the mandate is successfully created. A direct debit can be sent
        for this mandate ID.
          - Pending—a pending mandate means the mandate is not yet signed.
          - Failed—the customer did not authenticate.
          - Expired—the deadline to create the mandate passed.
          - Revoked—the mandate is cancelled.
        #### Paypal Billing Agreement:
        A billing agreement is set up between PayPal and your customer.
        When you collect the details of a customer’s billing agreement, you are able
        to bill that customer without requiring an authorization for each payment.
        You can bill the customer at the same time you process their PayPal Express
        checkout order, which simplifies your business processes.

        Args:
            id (str): ID for de-registration or cancellation of Billing Agreement
            body (ModifyBillingAgreement): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/billing-agreements/{id}")
            .http_method(HttpMethodEnum.PATCH)
            .template_param(Parameter()
                .key("id")
                .value(id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PtsV2ModifyBillingAgreementPost201Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2ModifyBillingAgreementPost400Response1Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2ModifyBillingAgreementPost502Response1Exception),
        ).execute()

    def billing_agreements_intimation(self,
                                      id,
                                      body):
        """Perform a POST request to
        /pts/v2/billing-agreements/{id}/intimations.

        Standing Instruction with or without Token.

        Args:
            id (str): ID for intimation of Billing Agreement
            body (IntimateBillingAgreement): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/billing-agreements/{id}/intimations")
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                .key("id")
                .value(id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PtsV2CreditsPost201Response1.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2CreditsPost400Response21Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2CreditsPost502Response21Exception),
        ).execute()
