"""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.payment_methods_for_order_get_200_response import (
    PaymentMethodsForOrderGet200Response,
)
from cellpointapi.models.payment_methods_search_vouchers_post_200_response import (
    PaymentMethodsSearchVouchersPost200Response,
)


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

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

    def orders_get_payment_methods(self,
                                   order_id):
        """Perform a GET request to
        /payments/v1/orders/{orderId}/payment-methods.

        Gets the payment methods available for a given order id.

        Args:
            order_id (str): Order to retrieve the payment methods that the buyer has
                available to pay for it with.

        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/orders/{orderId}/payment-methods")
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                .key("orderId")
                .value(order_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(Single("cpdIssuedJWT")),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PaymentMethodsForOrderGet200Response.from_dictionary)
            .is_api_response(True)
            .local_error("400", "Bad Request", ProblemException),
        ).execute()

    def orders_search_vouchers(self,
                               body=None):
        """Perform a POST request to /payments/v1/search-vouchers.

        Returns a list of available vouchers matching the search criteria.

        Args:
            body (SearchVouchersRequest, optional): Request body containing the
                search criteria.

        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/search-vouchers")
            .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(PaymentMethodsSearchVouchersPost200Response.from_dictionary)
            .is_api_response(True)
            .local_error("400", "Bad Request", ProblemException),
        ).execute()
