# -*- 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.prepaid_card_response import PrepaidCardResponse
from pqapiv2.models.prepaid_card_pin_token import PrepaidCardPinToken
from pqapiv2.models.users_prepaid_cards_pin_response import UsersPrepaidCardsPinResponse
from pqapiv2.models.prepaid_card_pin import PrepaidCardPin
from pqapiv2.models.prepaid_card_collection_response import PrepaidCardCollectionResponse
from pqapiv2.models.prepaid_card_request_response import PrepaidCardRequestResponse
from pqapiv2.models.prepaid_card_data_token_response import PrepaidCardDataTokenResponse
from pqapiv2.models.prepaid_card_data_response import PrepaidCardDataResponse


class PrepaidCardsController(BaseController):

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

    def replace_prepaid_card(self,
                             user_token,
                             dest_token,
                             x_my_pay_quicker_version,
                             body=None):
        """Does a POST request to /users/{user-token}/prepaid-cards/{dest-token}.

        Replace an existing Prepaid Card specifying the replacement reason and
        the card package for the replacement card.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            dest_token (string): Auto-generated unique identifier representing
                a transfer destination, including prepaid cards, bank
                accounts, paper checks, and other users, prefixed with
                <i>dest->.
            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:
            PrepaidCardResponse: 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 = '/users/{user-token}/prepaid-cards/{dest-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'dest-token': {'value': dest_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, PrepaidCardResponse.from_dictionary)

        return decoded

    def retrieve_prepaid_card(self,
                              user_token,
                              dest_token,
                              x_my_pay_quicker_version):
        """Does a GET request to /users/{user-token}/prepaid-cards/{dest-token}.

        Retrieve Prepaid Card details by destination token.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            dest_token (string): Auto-generated unique identifier representing
                a transfer destination, including prepaid cards, bank
                accounts, paper checks, and other users, prefixed with
                <i>dest->.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.

        Returns:
            PrepaidCardResponse: 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 = '/users/{user-token}/prepaid-cards/{dest-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'dest-token': {'value': dest_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
        }

        # 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, PrepaidCardResponse.from_dictionary)

        return decoded

    def update_prepaid_card_partial(self,
                                    user_token,
                                    dest_token,
                                    x_my_pay_quicker_version,
                                    body=None):
        """Does a PATCH request to /users/{user-token}/prepaid-cards/{dest-token}.

        Partial Prepaid Card update typically used when modifying card status.
        <i>*Does not require the entire object be passed in the request</i>

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            dest_token (string): Auto-generated unique identifier representing
                a transfer destination, including prepaid cards, bank
                accounts, paper checks, and other users, prefixed with
                <i>dest->.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            body (PrepaidCardStatus, optional): TODO: type description here.

        Returns:
            PrepaidCardResponse: 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 = '/users/{user-token}/prepaid-cards/{dest-token}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'dest-token': {'value': dest_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.patch(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _response = self.execute_request(_request)
        self.validate_response(_response)

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

        return decoded

    def generate_pin_operation_token(self,
                                     user_token,
                                     dest_token,
                                     x_my_pay_quicker_version):
        """Does a GET request to /users/{user-token}/prepaid-cards/{dest-token}/pin.

        Retrieve one part of a two-part token required to reveal or set a
        client side PIN. <i>*Not all programs support a reveal or set PIN
        operation.</i>

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            dest_token (string): Auto-generated unique identifier representing
                a transfer destination, including prepaid cards, bank
                accounts, paper checks, and other users, prefixed with
                <i>dest->.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.

        Returns:
            PrepaidCardPinToken: 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 = '/users/{user-token}/prepaid-cards/{dest-token}/pin'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'dest-token': {'value': dest_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
        }

        # 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, PrepaidCardPinToken.from_dictionary)

        return decoded

    def set_pin_if_supported(self,
                             user_token,
                             dest_token,
                             x_my_pay_quicker_version,
                             token,
                             card_pin):
        """Does a PUT request to /users/{user-token}/prepaid-cards/{dest-token}/pin.

        Allows the setting of a PIN if supported by program.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            dest_token (string): Auto-generated unique identifier representing
                a transfer destination, including prepaid cards, bank
                accounts, paper checks, and other users, prefixed with
                <i>dest->.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            token (string): Token used as part of a two-leg card PIN reveal
                request sent directly from the client, generally involving a
                second piece of data such as the CVV code on the back of a
                card.
            card_pin (string): Prepaid card PIN for ATM and Debit usage

        Returns:
            UsersPrepaidCardsPinResponse: 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 = '/users/{user-token}/prepaid-cards/{dest-token}/pin'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'dest-token': {'value': dest_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'token': token,
            'cardPin': card_pin
        }
        _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.put(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

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

        return decoded

    def reveal_pin_if_supported(self,
                                user_token,
                                dest_token,
                                x_my_pay_quicker_version,
                                token,
                                cvc_2,
                                body=None):
        """Does a POST request to /users/{user-token}/prepaid-cards/{dest-token}/pin.

        Reveals the PIN for a card where PIN reveal functionality is supported
        in the program and hosted by PayQuicker.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            dest_token (string): Auto-generated unique identifier representing
                a transfer destination, including prepaid cards, bank
                accounts, paper checks, and other users, prefixed with
                <i>dest->.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            token (string): Token used as part of a two-leg card PIN reveal
                request sent directly from the client, generally involving a
                second piece of data such as the CVV code on the back of a
                card.
            cvc_2 (string): Card Verification Value (CVV) located on the back
                of your credit card or debit card is a 3-digit number on VISA®
                and MasterCard® branded credit cards, and debit cards.
            body (object, optional): TODO: type description here.

        Returns:
            PrepaidCardPin: 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 = '/users/{user-token}/prepaid-cards/{dest-token}/pin'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'dest-token': {'value': dest_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'token': token,
            'cvc2': cvc_2
        }
        _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,
            '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, PrepaidCardPin.from_dictionary)

        return decoded

    def list_prepaid_cards(self,
                           user_token,
                           x_my_pay_quicker_version,
                           page=None,
                           page_size=20,
                           filter=None,
                           sort=None,
                           language=None):
        """Does a GET request to /users/{user-token}/prepaid-cards.

        Retrieve a list of all pre-paid cards by user token that supports
        filtering, sorting, and pagination through existing mechanisms.

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            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:
            PrepaidCardCollectionResponse: 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 = '/users/{user-token}/prepaid-cards'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True}
        })
        _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, PrepaidCardCollectionResponse.from_dictionary)

        return decoded

    def order_prepaid_card(self,
                           user_token,
                           x_my_pay_quicker_version,
                           body=None):
        """Does a POST request to /users/{user-token}/prepaid-cards.

        Order a pre-paid card for the user by specifying a cardPackage. <i>*A
        package defines the type of card, currency, artwork utilized, and
        often the method of delivery.</i>

        Args:
            user_token (string): Auto-generated unique identifier representing
                a user, prefixed with <i>user-</i>.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            body (PrepaidCardBase, optional): TODO: type description here.

        Returns:
            PrepaidCardRequestResponse: 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 = '/users/{user-token}/prepaid-cards'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_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, PrepaidCardRequestResponse.from_dictionary)

        return decoded

    def generate_prepaid_card_data_token(self,
                                         user_token,
                                         dest_token,
                                         x_my_pay_quicker_version,
                                         format,
                                         side=None):
        """Does a GET request to /users/{user-token}/prepaid-cards/{dest-token}/pci.

        Generate a token used to reveal prepaid card information in the form
        of image data (base64) or JSON.

        Args:
            user_token (string): TODO: type description here.
            dest_token (string): TODO: type description here.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            format (FormatEnum): Desired format for the prepaid card data.
            side (SideEnum, optional): Side to specify when retrieving a
                prepaid card's image data. *Required if IMAGE format
                specified.

        Returns:
            PrepaidCardDataTokenResponse: 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 = '/users/{user-token}/prepaid-cards/{dest-token}/pci'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'dest-token': {'value': dest_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'format': format,
            'side': side
        }
        _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, PrepaidCardDataTokenResponse.from_dictionary)

        return decoded

    def get_prepaid_card_data(self,
                              user_token,
                              dest_token,
                              x_my_pay_quicker_version,
                              format,
                              token,
                              side=None):
        """Does a POST request to /users/{user-token}/prepaid-cards/{dest-token}/pci.

        Return prepaid card data in the form of image data, text, or both.

        Args:
            user_token (string): TODO: type description here.
            dest_token (string): TODO: type description here.
            x_my_pay_quicker_version (string): Date-based API Version
                specified in the header <i>required</i> on all calls.
            format (FormatEnum): Desired format for the prepaid card data.
            token (string): Token used as part of a two-leg card PIN reveal
                request sent directly from the client, generally involving a
                second piece of data such as the CVV code on the back of a
                card.
            side (SideEnum, optional): Side to specify when retrieving a
                prepaid card's image data. *Required if IMAGE format
                specified.

        Returns:
            PrepaidCardDataResponse: 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 = '/users/{user-token}/prepaid-cards/{dest-token}/pci'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
            'user-token': {'value': user_token, 'encode': True},
            'dest-token': {'value': dest_token, 'encode': True}
        })
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'format': format,
            'token': token,
            'side': side
        }
        _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.post(_query_url, headers=_headers)
        _response = self.execute_request(_request)
        self.validate_response(_response)

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

        return decoded
