"""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_captures_voids_post_400_response_1_exception import (  # noqa: E501
    PtsV2CapturesVoidsPost400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_captures_voids_post_502_response_1_exception import (  # noqa: E501
    PtsV2CapturesVoidsPost502Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_credits_voids_post_400_response_1_exception import (  # noqa: E501
    PtsV2CreditsVoidsPost400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_credits_voids_post_502_response_1_exception import (  # noqa: E501
    PtsV2CreditsVoidsPost502Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_payments_voids_post_400_response_1_exception import (  # noqa: E501
    PtsV2PaymentsVoidsPost400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_payments_voids_post_502_response_1_exception import (  # noqa: E501
    PtsV2PaymentsVoidsPost502Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_refunds_voids_post_400_response_1_exception import (  # noqa: E501
    PtsV2RefundsVoidsPost400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_refunds_voids_post_502_response_1_exception import (  # noqa: E501
    PtsV2RefundsVoidsPost502Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_voids_post_400_response_1_exception import (  # noqa: E501
    PtsV2VoidsPost400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_voids_post_502_response_1_exception import (  # noqa: E501
    PtsV2VoidsPost502Response1Exception,
)
from visaacceptancemergedspec.http.http_method_enum import (
    HttpMethodEnum,
)
from visaacceptancemergedspec.models.pts_v_2_captures_voids_post_201_response import (
    PtsV2CapturesVoidsPost201Response,
)
from visaacceptancemergedspec.models.pts_v_2_credits_voids_post_201_response import (
    PtsV2CreditsVoidsPost201Response,
)
from visaacceptancemergedspec.models.pts_v_2_payments_voids_post_201_response import (
    PtsV2PaymentsVoidsPost201Response,
)
from visaacceptancemergedspec.models.pts_v_2_refunds_voids_post_201_response import (
    PtsV2RefundsVoidsPost201Response,
)
from visaacceptancemergedspec.models.pts_v_2_voids_post_200_response import (
    PtsV2VoidsPost200Response,
)


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

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

    def void_payment(self,
                     id,
                     body):
        """Perform a POST request to /pts/v2/payments/{id}/voids.

        Void a Payment API is only used, if you have requested Authorization and
        Capture together in [/pts/v2/payments]( API call. Include the payment ID in
        the POST request to cancel the payment.

        Args:
            id (str): The payment ID returned from a previous payment request.
            body (VoidPaymentRequest): 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/payments/{id}/voids")
            .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(PtsV2PaymentsVoidsPost201Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2PaymentsVoidsPost400Response1Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2PaymentsVoidsPost502Response1Exception),
        ).execute()

    def void_capture(self,
                     id,
                     body):
        """Perform a POST request to /pts/v2/captures/{id}/voids.

        Refund a capture API is only used, if you have requested Capture
        independenlty using [/pts/v2/payments/{id}/captures]( API call. Include the
        capture ID in the POST request to cancel the capture.

        Args:
            id (str): The capture ID returned from a previous capture request.
            body (VoidPaymentRequest): 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/captures/{id}/voids")
            .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(PtsV2CapturesVoidsPost201Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2CapturesVoidsPost400Response1Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2CapturesVoidsPost502Response1Exception),
        ).execute()

    def void_refund(self,
                    id,
                    body):
        """Perform a POST request to /pts/v2/refunds/{id}/voids.

        Include the refund ID in the POST request to cancel the refund.

        Args:
            id (str): The refund ID returned from a previous refund request.
            body (VoidPaymentRequest): 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/refunds/{id}/voids")
            .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(PtsV2RefundsVoidsPost201Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2RefundsVoidsPost400Response1Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2RefundsVoidsPost502Response1Exception),
        ).execute()

    def void_credit(self,
                    id,
                    body):
        """Perform a POST request to /pts/v2/credits/{id}/voids.

        Include the credit ID in the POST request to cancel the credit.

        Args:
            id (str): The credit ID returned from a previous credit request.
            body (VoidPaymentRequest): 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/credits/{id}/voids")
            .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(PtsV2CreditsVoidsPost201Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2CreditsVoidsPost400Response1Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2CreditsVoidsPost502Response1Exception),
        ).execute()

    def mit_void(self,
                 body):
        """Perform a POST request to /pts/v2/voids.

        This is to void a previous payment, capture, refund, or credit that merchant
        does not receive a reply(Mostly due to timeout). To use this feature/API,
        make sure to pass unique value to field - clientReferenceInformation ->
        transactionId in your payment, capture, refund, or credit API call and use
        same transactionId in this API request payload to reverse the payment.

        Args:
            body (MitVoidRequest): 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/voids")
            .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(PtsV2VoidsPost200Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2VoidsPost400Response1Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2VoidsPost502Response1Exception),
        ).execute()
