"""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_retrieve_payment_token_get_400_response_1_exception import (  # noqa: E501
    PtsV2RetrievePaymentTokenGet400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_retrieve_payment_token_get_502_response_1_exception import (  # noqa: E501
    PtsV2RetrievePaymentTokenGet502Response1Exception,
)
from visaacceptancemergedspec.http.http_method_enum import (
    HttpMethodEnum,
)
from visaacceptancemergedspec.models.retrieve_or_delete_payment_token_response import (
    RetrieveOrDeletePaymentTokenResponse,
)


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

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

    def retrieve_or_delete_payment_token(self,
                                         body):
        """Perform a POST request to /pts/v2/payment-tokens.

        This API can be used in two flavours - for retrieval or deletion of vault id.

        Args:
            body (Request): 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/payment-tokens")
            .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(RetrieveOrDeletePaymentTokenResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2RetrievePaymentTokenGet400Response1Exception)
            .local_error("502",
                "Internal server error.",
                PtsV2RetrievePaymentTokenGet502Response1Exception),
        ).execute()
