"""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,
)
from visaacceptancemergedspec.models.get_card_art_asset_response import (
    GetCardArtAssetResponse,
)


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

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

    def post_token_payment_credentials(self,
                                       token_id,
                                       body,
                                       profile_id=None):
        """Perform a POST request to
        /tms/v2/tokens/{tokenId}/payment-credentials.

        |  |  |  |
        | --- | --- | --- |
        |**Token**<br>A Token can represent your tokenized Customer, Payment
        Instrument or Instrument Identifier
        information.|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|**Payment
        Credentials**<br>Contains payment information such as the network token,
        generated cryptogram for Visa & MasterCard or dynamic CVV for Amex in a JSON
        Web Encryption (JWE) response.<br>Your system can use this API to retrieve
        the Payment Credentials for an existing Customer, Payment Instrument or
        Instrument Identifier.

        Args:
            token_id (str): The Id of a token representing a Customer, Payment
                Instrument or Instrument Identifier.
            body (PostPaymentCredentialsRequest): The request body parameter.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. A base64 encoded JSON
                Web Encryption (JWE) response containing encrypted Payment
                Credentials.

Example:
{
"kid":"a0eb65d572e556fddb68eb3a4078555605f7b2
                83",
"cty":"json",
"typ":"JWT",
"enc":"A256GCM",
"alg":"RSA-OAEP-256"
                }
[Encrypted Instrument Identifier Payment Credentials]

The
                encrypted Payment Credentials will contain the network token and
                cryptogram or dynamic CVV.

        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("/tms/v2/tokens/{tokenId}/payment-credentials")
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                .key("tokenId")
                .value(token_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json;charset=utf-8"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.dynamic_deserialize)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                ApiException)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                ApiException)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                ApiException)
            .local_error("410",
                "Token Not Available. The token has been deleted.",
                ApiException)
            .local_error("500", "Unexpected error.", ApiException),
        ).execute()

    def get_card_art_asset(self,
                           instrument_identifier_id,
                           token_provider,
                           asset_type):
        """Perform a GET request to
        /tms/v2/tokens/{instrumentIdentifierId}/{tokenProvider}/assets/{assetType}.

        Retrieves Card Art for a specific Instrument Identifier. The Card Art is a
        visual representation of the cardholder's payment card.
        Card Art is only available if a Network Token is successfully provisioned.

        Args:
            instrument_identifier_id (str): The Id of an Instrument Identifier.
            token_provider (TokenProvider1): The token provider.
            asset_type (AssetType1): The type of asset.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Returns the Card Art
                Asset Content of a Network Token

        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("/tms/v2/tokens/{instrumentIdentifierId}/{tokenProvider}/assets/{assetType}")
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                .key("instrumentIdentifierId")
                .value(instrument_identifier_id)
                .is_required(True)
                .should_encode(True))
            .template_param(Parameter()
                .key("tokenProvider")
                .value(token_provider)
                .is_required(True)
                .should_encode(True))
            .template_param(Parameter()
                .key("assetType")
                .value(asset_type)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(GetCardArtAssetResponse.from_dictionary)
            .is_api_response(True),
        ).execute()
