"""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 deprecation import deprecated

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.apple_tokenized_token import (
    AppleTokenizedToken,
)


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

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

    @deprecated()
    def apple_pay_store_encrypted_token(self,
                                        order_id,
                                        idempotency_key=None,
                                        body=None):
        """Perform a POST request to
        /payments/v1/orders/{orderId}/apple-pay-tokens.

        Stores an Apple Pay token for later use.

        Args:
            order_id (str): The order to store the Apple Pay token against.
            idempotency_key (uuid|str, optional): A unique identifier.  If you don't
                receive a response (for example, in case of a timeout), you can
                safely retry the request with the same header.  If the system already
                processed the request, the response to the first attempt will be
                returned without duplication.  Idempotency-Keys will last for 24hrs.
                After this time, please do a GET call to the resource to check the
                status.  > This is used only in `POST` requests, so they have the
                same idempotency guarantees as `PUT`.
            body (SavePkPaymentTokenRequest, optional): RequestBody containing the
                encrypted Apple Pay token.

        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}/apple-pay-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"))
            .header_param(Parameter()
                .key("Idempotency-Key")
                .value(idempotency_key))
            .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(AppleTokenizedToken.from_dictionary)
            .is_api_response(True)
            .local_error("400", "Bad Request", ProblemException),
        ).execute()
