# -*- coding: utf-8 -*-

"""
pqapiv2

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

from pqapiv2.api_helper import APIHelper
from pqapiv2.configuration import Server
from pqapiv2.controllers.base_controller import BaseController
from pqapiv2.models.payment_response import PaymentResponse
from pqapiv2.models.payments_collection_response import PaymentsCollectionResponse


class PaymentsController(BaseController):

    """A Controller to access Endpoints in the pqapiv2 API."""
    def __init__(self, config):
        super(PaymentsController, self).__init__(config)

    def retrieve_payment(self,
                         pmnt_token,
                         x_my_pay_quicker_version,
                         filter=None,
                         language=None):
        """Does a GET request to /payments/{pmnt-token}.

        Retrieve a list of all payments that supports filtering, sorting, and
        pagination through existing mechanisms.

        Args:
            pmnt_token (string): Auto-generated unique identifier representing
                an individual payment transaction and quote, prefixed with
                <i>pmnt-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            filter (string, optional): Filter request results by specific
                criteria.
            language (LanguageTypesEnum, optional): Filter results by language
                type.

        Returns:
            PaymentResponse: Response from the API. 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.

        """

        # Prepare query URL
        _url_path = '/payments/{pmnt-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'pmnt-token': {'value': pmnt_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'filter': filter,
            'language': language
        }
        _query_builder = APIHelper.append_url_with_query_parameters(
            _query_builder,
            _query_parameters
        )
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # Prepare and execute request
        _request = self.config.http_client.get(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, PaymentResponse.from_dictionary)

        return decoded

    def accept_payment_quote(self,
                             pmnt_token,
                             x_my_pay_quicker_version,
                             body=None):
        """Does a POST request to /payments/{pmnt-token}.

        Accept an open payment quote.

        Args:
            pmnt_token (string): Auto-generated unique identifier representing
                an individual payment transaction and quote, prefixed with
                <i>pmnt-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            body (object, optional): TODO: type description here.

        Returns:
            PaymentResponse: Response from the API. 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.

        """

        # Prepare query URL
        _url_path = '/payments/{pmnt-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'pmnt-token': {'value': pmnt_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version,
            'Content-Type': 'application/json'
        }

        # Prepare and execute request
        _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, PaymentResponse.from_dictionary)

        return decoded

    def cancel_payment_quote(self,
                             pmnt_token,
                             x_my_pay_quicker_version):
        """Does a DELETE request to /payments/{pmnt-token}.

        Cancel an open payment quote.

        Args:
            pmnt_token (string): Auto-generated unique identifier representing
                an individual payment transaction and quote, prefixed with
                <i>pmnt-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.

        Returns:
            void: Response from the API. 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.

        """

        # Prepare query URL
        _url_path = '/payments/{pmnt-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'pmnt-token': {'value': pmnt_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # Prepare and execute request
        _request = self.config.http_client.delete(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

    def retract_payment_full(self,
                             pmnt_token,
                             x_my_pay_quicker_version):
        """Does a PUT request to /payments/{pmnt-token}/retract.

        Perform a payment retraction for the full payment amount.

        Args:
            pmnt_token (string): Auto-generated unique identifier representing
                an individual payment transaction and quote, prefixed with
                <i>pmnt-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.

        Returns:
            void: Response from the API. 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.

        """

        # Prepare query URL
        _url_path = '/payments/{pmnt-token}/retract'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'pmnt-token': {'value': pmnt_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # Prepare and execute request
        _request = self.config.http_client.put(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

    def retract_payment_partial(self,
                                pmnt_token,
                                x_my_pay_quicker_version):
        """Does a PATCH request to /payments/{pmnt-token}/retract.

        Perform a payment retraction for a partial payment amount.

        Args:
            pmnt_token (string): Auto-generated unique identifier representing
                an individual payment transaction and quote, prefixed with
                <i>pmnt-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.

        Returns:
            void: Response from the API. 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.

        """

        # Prepare query URL
        _url_path = '/payments/{pmnt-token}/retract'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'pmnt-token': {'value': pmnt_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # Prepare and execute request
        _request = self.config.http_client.patch(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

    def list_payments(self,
                      x_my_pay_quicker_version,
                      page=None,
                      page_size=20,
                      filter=None,
                      sort=None,
                      language=None):
        """Does a GET request to /payments.

        Retrieve a list of all payments that supports filtering, sorting, and
        pagination through existing mechanisms.

        Args:
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            page (int, optional): Page number of specific page to return
            page_size (int, optional): Number of items to be displayed per
                page
            filter (string, optional): Filter request results by specific
                criteria.
            sort (string, optional): Sort request results by specific
                attribute.
            language (LanguageTypesEnum, optional): Filter results by language
                type.

        Returns:
            PaymentsCollectionResponse: Response from the API. 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.

        """

        # Prepare query URL
        _url_path = '/payments'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'page': page,
            'pageSize': page_size,
            'filter': filter,
            'sort': sort,
            'language': language
        }
        _query_builder = APIHelper.append_url_with_query_parameters(
            _query_builder,
            _query_parameters
        )
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version
        }

        # Prepare and execute request
        _request = self.config.http_client.get(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, PaymentsCollectionResponse.from_dictionary)

        return decoded

    def create_payment_quote(self,
                             x_my_pay_quicker_version,
                             body=None):
        """Does a POST request to /payments.

        Create a payment quote. 

        Args:
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            body (PaymentRequest, optional): TODO: type description here.

        Returns:
            PaymentResponse: Response from the API. 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.

        """

        # Prepare query URL
        _url_path = '/payments'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'X-MyPayQuicker-Version': x_my_pay_quicker_version,
            'Content-Type': 'application/json'
        }

        # Prepare and execute request
        _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = APIHelper.json_deserialize(_response.text, PaymentResponse.from_dictionary)

        return decoded
