"""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,
)
from cellpointapi.models.payments_v_1_bulks_response import (
    PaymentsV1BulksResponse,
)
from cellpointapi.models.summary import Summary


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

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

    def get_bulk_by_id(self,
                       bulk_id):
        """Perform a GET request to /payments/v1/bulks/{bulkId}.

        Get summary information about a bulk.

        Args:
            bulk_id (str): Bulk to retrieve

        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/bulks/{bulkId}")
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                .key("bulkId")
                .value(bulk_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(Summary.from_dictionary)
            .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()

    def trigger_bulk(self,
                     request):
        """Perform a POST request to /payments/v1/bulks.

        Trigger a bulk.

        Args:
            request (TriggerBulkRequest): Bulk request to trigger.

        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/bulks")
            .http_method(HttpMethodEnum.POST)
            .query_param(Parameter()
                .key("request")
                .value(request)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(Single("cpdIssuedJWT")),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PaymentsV1BulksResponse.from_dictionary)
            .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()
