"""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.api_exception import (
    ApiException,
)
from cellpointapi.exceptions.problem_exception import (
    ProblemException,
)
from cellpointapi.http.http_method_enum import (
    HttpMethodEnum,
)


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

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

    def document_proxy(self,
                       target_host,
                       target_endpoint,
                       target_authentication,
                       target_json_path_card_number,
                       target_json_path_expiry_date,
                       target_json_path_security_code,
                       body):
        """Perform a POST request to /payments/v1/document-proxy.

        A client can use this endpoint to transmit card data to a third party. The
        third party can then use the card data to process a payment on behalf of the
        client.
        The client is never in possession of the card data. The third party is
        responsible for the security of the card data.
        Third parties must be registered with Cellpoint and configured to receive
        card data from the client.
        The client must have a valid access token to use this endpoint.

        Args:
            target_host (str): Host where the request will be forwarded. Must have
                been previously registered with Cellpoint.
            target_endpoint (str): Endpoint where the request will be forwarded.
            target_authentication (str): Contains a token which will be used to
                authenticate the request to the target server.
            target_json_path_card_number (str): Contains the JSON Path of the PAN
                field in the request. In the body, this field should contain the
                Cellpoint generated token which is associated with the card data.
            target_json_path_expiry_date (str): Contains the JSON Path of the expiry
                date field in the request.
            target_json_path_security_code (str): Contains the JSON Path of the
                security code field in the request.
            body (Any): The request body must be a JSON object. The object will be
                forwarded to the target server, with the paths specified in the
                headers replaced with the card data.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. OK - The response will
                be passed from the target server to the client.

        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/document-proxy")
            .http_method(HttpMethodEnum.POST)
            .header_param(Parameter()
                .key("Target-Host")
                .value(target_host)
                .is_required(True))
            .header_param(Parameter()
                .key("Target-Endpoint")
                .value(target_endpoint)
                .is_required(True))
            .header_param(Parameter()
                .key("Target-Authentication")
                .value(target_authentication)
                .is_required(True))
            .header_param(Parameter()
                .key("Target-Json-Path-Card-Number")
                .value(target_json_path_card_number)
                .is_required(True))
            .header_param(Parameter()
                .key("Target-Json-Path-Expiry-Date")
                .value(target_json_path_expiry_date)
                .is_required(True))
            .header_param(Parameter()
                .key("Target-Json-Path-Security-Code")
                .value(target_json_path_security_code)
                .is_required(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .body_serializer(APIHelper.json_serialize)
            .auth(Single("cpdIssuedJWT")),
        ).response(
            ResponseHandler()
            .is_api_response(True)
            .local_error("400", "Bad Request", ProblemException)
            .local_error("401", "Authorization Required", ApiException)
            .local_error("404", "Resource Not Found", ApiException)
            .local_error("406",
                "Cannot generate content acceptable according to the `Accept` headers"
                " in the request",
                ProblemException)
            .local_error("500", "Internal Server Error", ProblemException)
            .local_error("502", "Bad Gateway", ApiException)
            .local_error("503", "Service Unavailable", ApiException),
        ).execute()
