# -*- 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.bank_account_collection_response import BankAccountCollectionResponse
from pqapiv2.models.bank_account_response import BankAccountResponse
from pqapiv2.models.bank_account_requirement_collection_response import BankAccountRequirementCollectionResponse


class BankAccountsController(BaseController):

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

    def list_bank_accounts(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}/bank-accounts.

        Retrieve a list of bank accounts 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:
            BankAccountCollectionResponse: 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}/bank-accounts'
        _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, BankAccountCollectionResponse.from_dictionary)

        return decoded

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

        Create a quote for a bank account using a user token.

        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 (BankAccountFields, optional): TODO: type description here.

        Returns:
            BankAccountResponse: 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}/bank-accounts'
        _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, BankAccountResponse.from_dictionary)

        return decoded

    def retrieve_bank_account(self,
                              user_token,
                              dest_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}/bank-accounts/{dest-token}.

        Retrieve a list of bank accounts using a destination 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>.
            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.
            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:
            BankAccountResponse: 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}/bank-accounts/{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_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, BankAccountResponse.from_dictionary)

        return decoded

    def update_bank_account(self,
                            user_token,
                            dest_token,
                            x_my_pay_quicker_version,
                            body=None):
        """Does a PUT request to /users/{user-token}/bank-accounts/{dest-token}.

        Update a bank account.

        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 (BankAccountFields, optional): TODO: type description here.

        Returns:
            BankAccountResponse: 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}/bank-accounts/{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.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        _response = self.execute_request(_request)
        self.validate_response(_response)

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

        return decoded

    def delete_bank_account(self,
                            user_token,
                            dest_token,
                            x_my_pay_quicker_version):
        """Does a DELETE request to /users/{user-token}/bank-accounts/{dest-token}.

        Delete (cloak) a user bank account.

        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:
            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 = '/users/{user-token}/bank-accounts/{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 = {
            '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 get_bank_account_requirements(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}/bank-accounts/requirements.

        Retrieve requirements for adding a bank account using the parameters
        provided (user context, given country of residence, supported EFT
        provider(s), destination currency, destination country, required
        fields, with names, and regex validation expression) for easy customer
        wire-up and validation.

        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:
            BankAccountRequirementCollectionResponse: 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}/bank-accounts/requirements'
        _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, BankAccountRequirementCollectionResponse.from_dictionary)

        return decoded
