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

"""
pqapiv2

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

import json
import dateutil.parser

from tests.controllers.controller_test_base import ControllerTestBase
from tests.test_helper import TestHelper
from pqapiv2.api_helper import APIHelper


class BalancesControllerTests(ControllerTestBase):

    @classmethod
    def setUpClass(cls):
        super(BalancesControllerTests, cls).setUpClass()
        cls.controller = cls.client.balances
        cls.response_catcher = cls.controller.http_call_back

    # Retrieve a list of user balances that supports filtering, sorting, and pagination through existing mechanisms.
    def test_list_user_balances(self):
        # Parameters for the API call
        user_token = 'user-f012bc86-4d42-415b-a8b2-be5e0b90e59a'
        x_my_pay_quicker_version = '2020.02.24'
        page = None
        page_size = 20
        filter = '\'name\'*\'Fra\'||*\'Ger\',\'numericCode\'>\'5\''
        sort = '-name'
        language = 'en-US'

        # Perform the API call through the SDK function
        result = self.controller.list_user_balances(user_token, x_my_pay_quicker_version, page, page_size, filter, sort, language)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize('{"payload":[{"formattedAmount":"$4.32 USD","amount":4.32,"currency'
            '":"USD","token":"dest-4aed86e2-4929-45bf-814d-9030aef21e79","links'
            '":[{"params":{"rel":"self"},"href":"https://platform.mypayquicker.'
            'com/api/v2/users/user-f012bc86-4d42-415b-a8b2-be5e0b90e59a/prepaid'
            '-cards/dest-4aed86e2-4929-45bf-814d-9030aef21e79/balances"}]}],"li'
            'nks":[{"params":{"rel":"self"},"href":"https://platform.mypayquick'
            'er.com/api/v2/users/user-f012bc86-4d42-415b-a8b2-be5e0b90e59a/bala'
            'nces"}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

    # Retrieve a list of balances by destination token that supports filtering, sorting, and pagination through existing mechanisms. <i>*If the user belongs to a Flex-based program, balances against the user resource will return the wallet balance only. If it is a pre-paid card program (i.e., Meta USD), this balance and its associated pre-paid card balance will be the same.</i>
    def test_list_prepaid_card_balance(self):
        # Parameters for the API call
        user_token = 'user-f012bc86-4d42-415b-a8b2-be5e0b90e59a'
        dest_token = 'dest-4aed86e2-4929-45bf-814d-9030aef21e79'
        x_my_pay_quicker_version = '2020.02.24'
        page = None
        page_size = 20
        filter = '\'name\'*\'Fra\'||*\'Ger\',\'numericCode\'>\'5\''
        sort = '-name'
        language = 'en-US'

        # Perform the API call through the SDK function
        result = self.controller.list_prepaid_card_balance(user_token, dest_token, x_my_pay_quicker_version, page, page_size, filter, sort, language)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize('{"formattedAmount":"$4.32","amount":4.32,"currency":"USD","token":'
            '"dest-4aed86e2-4929-45bf-814d-9030aef21e79","links":[{"params":{"r'
            'el":"self"},"href":"https://platform.mypayquicker.com/api/v2/users'
            '/user-f012bc86-4d42-415b-a8b2-be5e0b90e59a/prepaid-cards/dest-4aed'
            '86e2-4929-45bf-814d-9030aef21e79/balances"}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

    # Retrieve a single account balance.
    def test_list_account_balances(self):
        # Parameters for the API call
        acct_token = 'acct-b3f0570a-6586-4e00-8d6e-8a2bf93cfae4'
        x_my_pay_quicker_version = '2020.02.24'
        page = None
        page_size = 20
        filter = '\'name\'*\'Fra\'||*\'Ger\',\'numericCode\'>\'5\''
        sort = '-name'
        language = 'en-US'

        # Perform the API call through the SDK function
        result = self.controller.list_account_balances(acct_token, x_my_pay_quicker_version, page, page_size, filter, sort, language)

        # Test response code
        self.assertEquals(self.response_catcher.response.status_code, 200)

        # Test headers
        expected_headers = {}
        expected_headers['content-type'] = 'application/json'

        self.assertTrue(TestHelper.match_headers(expected_headers, self.response_catcher.response.headers))

        
        # Test whether the captured response is as we expected
        self.assertIsNotNone(result)
        expected_body = APIHelper.json_deserialize('{"payload":[{"formattedAmount":"$5.00","amount":5,"currency":"USD"'
            ',"token":"acct-b3f0570a-6586-4e00-8d6e-8a2bf93cfae4"}],"links":[{"'
            'params":{"rel":"self"},"href":"https://platform.mypayquicker.com/a'
            'pi/v2/accounts/acct-b3f0570a-6586-4e00-8d6e-8a2bf93cfae4/balances"'
            '}]}')
        received_body = APIHelper.json_deserialize(self.response_catcher.response.text)
        self.assertTrue(TestHelper.match_body(expected_body, received_body))

