"""cellpointapi.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: D410, E501, E101, D206
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 cellpointapi.api_helper import APIHelper
from cellpointapi.apis.base_api import BaseApi
from cellpointapi.configuration import Server
from cellpointapi.exceptions.problem_exception import (
    ProblemException,
)
from cellpointapi.http.http_method_enum import (
    HttpMethodEnum,
)
from cellpointapi.models.payments_v_1_schemes_response import (
    PaymentsV1SchemesResponse,
)
from cellpointapi.models.tokenized_card import (
    TokenizedCard,
)
from cellpointapi.models.tokenized_card_with_contact_data import (
    TokenizedCardWithContactData,
)


class CardsApi(BaseApi):
    """A Controller to access Endpoints in the cellpointapi API."""

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

    def card_tokenize(self,
                      order_id,
                      body=None):
        """Perform a POST request to /payments/v1/orders/{orderId}/card-tokens.

        Tokenize a card to use for a later authorization.
        Tokenization is useful to prevent other parts system from having to interact
        with PCI information.
        Tokens are single-use and will expire after 15 minutes.

        Args:
            order_id (str): Order to retrieve the payment methods that the buyer has
                available to pay for it with.
            body (Card, optional): Request body containing the card details.

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

        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("/payments/v1/orders/{orderId}/card-tokens")
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                .key("orderId")
                .value(order_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(Single("cpdIssuedJWT")),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(TokenizedCard.from_dictionary)
            .is_api_response(True)
            .local_error("400", "Bad Request", ProblemException),
        ).execute()

    def external_card_tokenize(self,
                               order_id,
                               body=None):
        """Perform a POST request to
        /payments/v1/orders/{orderId}/external-card-tokens.

        Tokenize an externally tokenized data to use for a later authorization.
        Tokenization is useful to prevent other parts system from having to interact
        with PCI information.
        Tokens are single-use and will expire after 15 minutes.
        Unlike the regular tokenization, this endpoint is used to tokenize data that
        has already been tokenized by a third party,
        such as a payment gateway or a wallet provider. Such data typically billing
        details too.
        This endpoint will return these billing details.

        Args:
            order_id (str): Order to retrieve the payment methods that the buyer has
                available to pay for it with.
            body (ExternallyTokenizedCard, optional): Request body containing the
                card details.

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

        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("/payments/v1/orders/{orderId}/external-card-tokens")
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                .key("orderId")
                .value(order_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(Single("cpdIssuedJWT")),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(TokenizedCardWithContactData.from_dictionary)
            .is_api_response(True)
            .local_error("400", "Bad Request", ProblemException),
        ).execute()

    def card_scheme_lookup(self,
                           body=None):
        """Perform a POST request to /payments/v1/schemes.

        Lookup the card scheme via BIN data.

        Args:
            body (Bin, optional): Request body containing the card BIN.

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

        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("/payments/v1/schemes")
            .http_method(HttpMethodEnum.POST)
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(Single("cpdIssuedJWT")),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PaymentsV1SchemesResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400", "Bad Request", ProblemException),
        ).execute()
