"""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.api_exception import (
    ApiException,
)
from visaacceptancemergedspec.http.http_method_enum import (
    HttpMethodEnum,
)


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

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

    def get_transaction_for_transient_token(self,
                                            transient_token):
        """Perform a GET request to /up/v1/payment-details/{transientToken}.

        Retrieve the data captured by Unified Checkout. This API is used to retrieve
        the detailed data represented by the Transient Token. This API will not
        return PCI payment data (PAN). Include the Request ID in the GET request to
        retrieve the transaction details.

        Args:
            transient_token (str): Transient Token returned by the Unified Checkout
                application.

        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("/up/v1/payment-details/{transientToken}")
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                .key("transientToken")
                .value(transient_token)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .is_api_response(True)
            .local_error("404",
                "The specified resource not found in the system.",
                ApiException)
            .local_error("500", "Unexpected server error", ApiException),
        ).execute()

    def get_payment_credentials_for_transient_token(self,
                                                    payment_credentials_reference):
        """Perform a GET request to
        /flex/v2/payment-credentials/{paymentCredentialsReference}.

        Retrieve the Payment data captured by Unified Checkout. This API is used to
        retrieve the detailed data represented by the Transient Token. This API will
        return PCI payment data captured by the Unified Checkout platform.

        Args:
            payment_credentials_reference (str): The paymentCredentialsReference
                field contained within the Transient token returned from a successful
                Unified Checkout transaction

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

        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("/flex/v2/payment-credentials/{paymentCredentialsReference}")
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                .key("paymentCredentialsReference")
                .value(payment_credentials_reference)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.dynamic_deserialize)
            .is_api_response(True)
            .local_error("404",
                "The specified resource not found in the system.",
                ApiException)
            .local_error("500", "Unexpected server error", ApiException),
        ).execute()
