"""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 UnifiedCheckoutCaptureContextApi(BaseApi):
    """A Controller to access Endpoints in the visaacceptancemergedspec API."""

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

    def generate_unified_checkout_capture_context(self,
                                                  body):
        """Perform a POST request to /up/v1/capture-contexts.

        Unified Checkout is a powerful product within the Digital Acceptance Suite.
        Unified Checkout is designed to assist merchants with the adoption and
        inclusion of digital payments within their payment acceptance page. With
        Unified Checkout Integration you can add digital payment methods to create
        familiar, convenient and seamless payment experiences that are designed to
        reduce checkout friction and increase conversions.
        Click to Pay Drop-in UI is built on the Unified Checkout platform.
        For more information about Unified Checkout, see the [Unified Checkout
        Developer Guides Page]( For examples on how to integrate Unified Checkout
        within your webpage please see our [GitHub Unified Checkout Samples](
        Generate Unified Checkout Capture Context
        Generate a one-time use capture context used for the invocation of Unified
        Checkout. The Request wil contain all of the parameters for how Unified
        Checkout will operate within a client webpage. The resulting payload will be
        a JWT signed object that can be used to initiate Unified Checkout or Click to
        Pay Drop-in UI within a web page

        Args:
            body (GenerateUnifiedCheckoutCaptureContextRequest): The request body
                parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Capture Context 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("/up/v1/capture-contexts")
            .http_method(HttpMethodEnum.POST)
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .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", ApiException),
        ).execute()
