"""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.delete_tokenized_card_exception_1_exception import (  # noqa: E501
    DeleteTokenizedCardException1Exception,
)
from visaacceptancemergedspec.exceptions.delete_tokenized_card_exception_21_exception import (  # noqa: E501
    DeleteTokenizedCardException21Exception,
)
from visaacceptancemergedspec.exceptions.delete_tokenized_card_exception_31_exception import (  # noqa: E501
    DeleteTokenizedCardException31Exception,
)
from visaacceptancemergedspec.exceptions.delete_tokenized_card_exception_41_exception import (  # noqa: E501
    DeleteTokenizedCardException41Exception,
)
from visaacceptancemergedspec.exceptions.delete_tokenized_card_exception_61_exception import (  # noqa: E501
    DeleteTokenizedCardException61Exception,
)
from visaacceptancemergedspec.exceptions.get_tokenized_card_exception_1_exception import (  # noqa: E501
    GetTokenizedCardException1Exception,
)
from visaacceptancemergedspec.exceptions.get_tokenized_card_exception_21_exception import (  # noqa: E501
    GetTokenizedCardException21Exception,
)
from visaacceptancemergedspec.exceptions.get_tokenized_card_exception_31_exception import (  # noqa: E501
    GetTokenizedCardException31Exception,
)
from visaacceptancemergedspec.exceptions.get_tokenized_card_exception_51_exception import (  # noqa: E501
    GetTokenizedCardException51Exception,
)
from visaacceptancemergedspec.exceptions.post_tokenized_card_exception_1_exception import (  # noqa: E501
    PostTokenizedCardException1Exception,
)
from visaacceptancemergedspec.exceptions.post_tokenized_card_exception_21_exception import (  # noqa: E501
    PostTokenizedCardException21Exception,
)
from visaacceptancemergedspec.exceptions.post_tokenized_card_exception_31_exception import (  # noqa: E501
    PostTokenizedCardException31Exception,
)
from visaacceptancemergedspec.exceptions.post_tokenized_card_exception_41_exception import (  # noqa: E501
    PostTokenizedCardException41Exception,
)
from visaacceptancemergedspec.exceptions.post_tokenized_card_exception_51_exception import (  # noqa: E501
    PostTokenizedCardException51Exception,
)
from visaacceptancemergedspec.http.http_method_enum import (
    HttpMethodEnum,
)
from visaacceptancemergedspec.models.get_tokenized_card_response import (
    GetTokenizedCardResponse,
)
from visaacceptancemergedspec.models.post_tokenized_card_response import (
    PostTokenizedCardResponse,
)


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

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

    def post_tokenized_card(self,
                            body,
                            profile_id=None):
        """Perform a POST request to /tms/v2/tokenized-cards.

        |  |  |  |
        | --- | --- | --- |
        |**Tokenized cards**<br>A Tokenized card represents a network token. Network
        tokens perform better than regular card numbers and they are not necessarily
        invalidated when a cardholder loses their card, or it expires.

        Args:
            body (TokenizedcardRequest): 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. Returns an existing
                tokenized card associated with the supplied Id.

        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/tokenized-cards")
            .http_method(HttpMethodEnum.POST)
            .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.json_deserialize)
            .deserialize_into(PostTokenizedCardResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                PostTokenizedCardException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                PostTokenizedCardException21Exception)
            .local_error("409",
                "Conflict. The token is linked to a Payment Instrument.",
                PostTokenizedCardException31Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                PostTokenizedCardException41Exception)
            .local_error("500",
                "Unexpected error.",
                PostTokenizedCardException51Exception),
        ).execute()

    def get_tokenized_card(self,
                           tokenized_card_id,
                           profile_id=None):
        """Perform a GET request to /tms/v2/tokenized-cards/{tokenizedCardId}.

        |  |  |  |
        | --- | --- | --- |
        |**Tokenized Cards**<br>A Tokenized Card represents a network token.
        Network tokens perform better than regular card numbers and they are not
        necessarily invalidated when a cardholder loses their card, or it expires.

        Args:
            tokenized_card_id (str): The Id of a tokenized card.
            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. Returns an existing
                tokenized card associated with the supplied Id.

        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/tokenized-cards/{tokenizedCardId}")
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                .key("tokenizedCardId")
                .value(tokenized_card_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(GetTokenizedCardResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                GetTokenizedCardException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                GetTokenizedCardException21Exception)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                GetTokenizedCardException31Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                GetTokenizedCardException31Exception)
            .local_error("500",
                "Unexpected error.",
                GetTokenizedCardException51Exception),
        ).execute()

    def delete_tokenized_card(self,
                              tokenized_card_id,
                              profile_id=None):
        """Perform a DELETE request to
        /tms/v2/tokenized-cards/{tokenizedCardId}.

        |  |  |  |
        | --- | --- | --- |
        | The Network Token will attempt to be deleted from the card association and
        if successful the corresponding TMS Network Token will be deleted.

        Args:
            tokenized_card_id (str): The Id of a tokenized card.
            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. The request is
                fulfilled but does not need to return a body

        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/tokenized-cards/{tokenizedCardId}")
            .http_method(HttpMethodEnum.DELETE)
            .template_param(Parameter()
                .key("tokenizedCardId")
                .value(tokenized_card_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .is_api_response(True)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                DeleteTokenizedCardException1Exception)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                DeleteTokenizedCardException21Exception)
            .local_error("409",
                "Conflict. The token is linked to a Payment Instrument.",
                DeleteTokenizedCardException31Exception)
            .local_error("410",
                "Token Not Available. The token has been deleted.",
                DeleteTokenizedCardException41Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                DeleteTokenizedCardException21Exception)
            .local_error("500",
                "Unexpected error.",
                DeleteTokenizedCardException61Exception),
        ).execute()
