package cz.moneta.test.regression.transactional.payments.cashless.payment_engine.domestic.analytical;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.payment_engine.enums.AccountStates;
import cz.moneta.test.dsl.payment_engine.enums.TransactionReasonPAE;
import cz.moneta.test.dsl.payment_engine.tasks.PaymentEngineTasks;
import cz.moneta.test.dsl.payment_engine.utils.PaymentEngineUtils;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.payment.PaymentData;
import cz.moneta.test.harness.annotations.Environment;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;

import java.util.concurrent.ThreadLocalRandom;

import static cz.moneta.test.dsl.payment_engine.PaymentEngineDetailAccountPage.ACC_BALANCE_VALUE_KEY;
import static cz.moneta.test.dsl.payment_engine.PaymentEngineDetailAccountPage.DISPO_BALANCE_VALUE_KEY;
import static cz.moneta.test.dsl.payment_engine.enums.AccountStates.*;
import static cz.moneta.test.dsl.payment_engine.enums.TransactionReasonPAE.*;
import static cz.moneta.test.dsl.ufo.banka.pages.products.current.account.HPO001_S001_CurrentAccountDetailsPage.ACC_BALANCE_KEY;
import static cz.moneta.test.dsl.ufo.banka.pages.products.current.account.HPO001_S001_CurrentAccountDetailsPage.DISPO_BALANCE_KEY;

@TestScenarioWithOrder(name = "Create domestic instant payment")
public class InstantPaymentErrors {
    private String TOKEN_CBL;
    private PaymentData data;
    private PaymentEngineTasks paymentEngineTasks;
    private BankaTasks bankaTasks;
    private String transactionId;

    @BeforeAll
    void setUpTestData(Harness harness) {
        data = PaymentData.builder()
                .accPrefix(harness.getConfig("payments_cashless.domesticPayment.accPrefixForExternal1"))
                .bankCode("0600 - MONETA Money Bank, a.s.")
                .build();
        TOKEN_CBL = harness.tasks().wso2().authorization().getToken("DigitalchannelsSB_CBL");
    }

    @BeforeEach
    void setUpUniqueTestData(Harness harness) {
        data.setAmount(ThreadLocalRandom.current().nextInt(25, 50) + "," + ThreadLocalRandom.current().nextInt(10, 99));
        paymentEngineTasks = harness.tasks().paymentEngineTasks();
        bankaTasks = harness.tasks().ufo().banka();
    }

    private void changeClientsAccountState(Harness harness, String account, AccountStates clientsAccountState) {
        String request = harness.tasks()
                .wso2()
                .payments()
                .createRequestForClientsAccountStateChange(account, clientsAccountState);
        harness.tasks()
                .wso2()
                .payments()
                .changeClientsAccountState(TOKEN_CBL, request);
    }

    private void createAndVerifyTransactionWithoutPrefix(Harness harness, Credentials user1, Credentials user2, TransactionReasonPAE status) {
        paymentEngineTasks.loginTasks().logInPae(harness, user1)
                .then(paymentEngineTasks.createInstantTransactionWithoutPrefix(data));
        transactionId = PaymentEngineUtils.getTransactionalId(harness);
        harness.withPaymentEngine().closePaymentEngine();

        paymentEngineTasks.loginTasks().logInPae(harness, user2)
                .then(paymentEngineTasks.verifyAndWaitForStatus(transactionId, status));
        harness.withPaymentEngine().closePaymentEngine();
    }

    private void createAndVerifyTransactionWithPrefix(Harness harness, Credentials user1, Credentials user2, TransactionReasonPAE status) {
        paymentEngineTasks.loginTasks().logInPae(harness, user1)
                .then(paymentEngineTasks.createInstantTransactionWithPrefix(data));
        String transactionId = PaymentEngineUtils.getTransactionalId(harness);
        harness.withPaymentEngine().closePaymentEngine();

        paymentEngineTasks.loginTasks().logInPae(harness, user2)
                .then(paymentEngineTasks.verifyAndWaitForStatus(transactionId, status));
        harness.withPaymentEngine().closePaymentEngine();
    }

    private void checkAccountState(Harness harness, Credentials user1, PaymentData data, AccountStates state) {
        paymentEngineTasks.loginTasks().logInPae(harness, user1)
                .then(paymentEngineTasks.checkAccountState(data.getDebtorAcc(), state));
        harness.withPaymentEngine().closePaymentEngine();
    }

    @Order(1)
    @JiraTestCase(id = "PAY-T2887")
    @TestCase(name = "HD:02 - Create Internal to Internal transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentIntToIntAndCompareBalancesWithUfo(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials paeCredentials1,
                                                               @Key(Keys.paymentEngine.secondUser) Credentials paeCredentials2,
                                                               @Key(Keys.ufo.banka.banker) Credentials ufoCredentials) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAccBalances"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.creditorAccInt"));

        paymentEngineTasks.loginTasks().logInPae(harness, paeCredentials1)
                .then(paymentEngineTasks.storeBalancesFromCache24(data))
                .closeTab()
                .then(paymentEngineTasks.createInstantTransactionWithoutPrefix(data));
        String transactionId = PaymentEngineUtils.getTransactionalId(harness);
        harness.withPaymentEngine().closePaymentEngine();

        String dispoBalancePaymentEngine = harness.get(DISPO_BALANCE_VALUE_KEY);
        String accBalancePaymentEngine = harness.get(ACC_BALANCE_VALUE_KEY);
        double dispoBalancePaymentEngineDouble = parseValueGlobalStorePaymentEngine(dispoBalancePaymentEngine);
        double accBalancePaymentEngineDouble = parseValueGlobalStorePaymentEngine(accBalancePaymentEngine);

        paymentEngineTasks.loginTasks().logInPae(harness, paeCredentials2)
                .then(paymentEngineTasks.verifyAndWaitForStatus(transactionId, ARCHIV))
                .wait5sec() //UFO cannot book transaction faster than 5 seconds
                .closeTab()
                .then(paymentEngineTasks.storeBalancesFromCache24(data));
        harness.withPaymentEngine().closePaymentEngine();

        String newDispoBalancePaymentEngine = harness.get(DISPO_BALANCE_VALUE_KEY);
        String newAccBalancePaymentEngine = harness.get(ACC_BALANCE_VALUE_KEY);
        double newDispoBalancePaymentEngineDouble = parseValueGlobalStorePaymentEngine(newDispoBalancePaymentEngine);
        double newAccBalancePaymentEngineDouble = parseValueGlobalStorePaymentEngine(newAccBalancePaymentEngine);

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentials(ufoCredentials))
                .then(bankaTasks.payment().searchAccountByProduct(data.getDebtorAcc()))
                .then(bankaTasks.payment().storeBalancesFromUfoBanka());
        harness.withUfo().closeApplication();

        double newDispoBalanceUfo = parseValueGlobalStorePaymentEngine(harness.get(DISPO_BALANCE_KEY));
        double newAccBalanceUfo = parseValueGlobalStorePaymentEngine(harness.get(ACC_BALANCE_KEY));

        harness.store("reports.tmfj.execution.comment", "Transaction " + transactionId + " was successfully verified"
                + "\n"
                + "Debtor account: " + data.getDebtorAcc()
                + "\n"
                + "Creditor account: " + data.getCreditorAcc() + "/" + data.getBankCode()
                + "\n"
                + "Amount: " + data.getAmount() + " CZK"
                + "\n"
                + "Previous Dispo balance in PAE and UFO: " + dispoBalancePaymentEngine
                + "\n"
                + "New Dispo balance in PAE and UFO: " + newDispoBalancePaymentEngine
                + "\n"
                + "Previous Acc balance in PAE and UFO: " + accBalancePaymentEngine
                + "\n"
                + "New Acc balance in PAE and UFO: " + newAccBalancePaymentEngine);

        Long expectedDispoBalancePaymentEngineDouble = Math.round(Double.valueOf(dispoBalancePaymentEngineDouble - parseValueGlobalStorePaymentEngine(data.getAmount())));
        Long expectedAccBalancePaymentEngineDouble = Math.round(Double.valueOf(accBalancePaymentEngineDouble - parseValueGlobalStorePaymentEngine(data.getAmount())));

        Assertions.assertEquals(expectedDispoBalancePaymentEngineDouble, Math.round(newDispoBalancePaymentEngineDouble));
        Assertions.assertEquals(expectedAccBalancePaymentEngineDouble, Math.round(newAccBalancePaymentEngineDouble));
        Assertions.assertEquals(newDispoBalancePaymentEngineDouble, newDispoBalanceUfo);
        Assertions.assertEquals(newAccBalancePaymentEngineDouble, newAccBalanceUfo);
        harness.log("Transaction " + transactionId + " was successfully verified");

    }

    @Order(2)
    @JiraTestCase(id = "PAY-T2874")
    @TestCase(name = "HD:02 - Create Closed to Normal transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentClosedToNormal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                            @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.closedAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));

        changeClientsAccountState(harness, data.getDebtorAcc(), SLEEPING);

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, CLOSED_DEBTOR);
        String transactionId1 = transactionId;

        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.closedAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, REJECT);
        String transactionId2 = transactionId;

        changeClientsAccountState(harness, data.getCreditorAcc(), ACTIVE);

        PaymentEngineUtils.logResultLong(harness, transactionId1, transactionId2, data);
    }

    @Order(3)
    @JiraTestCase(id = "PAY-T2878")
    @TestCase(name = "HD:02 - Create Sleeping account to Normal transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentRestingToNormal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                             @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.sleepingAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, SLEEPING_DEBTOR);
        String transactionId1 = transactionId;

        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.sleepingAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, ARCHIV);
        String transactionId2 = transactionId;

        PaymentEngineUtils.logResultLong(harness, transactionId1, transactionId2, data);
    }

    @Order(4)
    @JiraTestCase(id = "PAY-T2875")
    @TestCase(name = "HD:02 - Create Closed (State 7) to Internal transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentClosedState7ToNormal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                                  @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.closedState7"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, BLOCKED_DEBTOR);
        String transactionId1 = transactionId;

        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.closedState7"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, REJECT);
        String transactionId2 = transactionId;

        PaymentEngineUtils.logResultLong(harness, transactionId1, transactionId2, data);
    }

    @Order(5)
    @JiraTestCase(id = "PAY-T2866")
    @TestCase(name = "HD:02 - Create Blocked to Internal transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentBlockedToNormal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                             @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.blockedDebitsAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, BLOCKED_DEBTOR);
        String transactionId1 = transactionId;

        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.blockedDebitsAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, ARCHIV);
        String transactionId2 = transactionId;

        PaymentEngineUtils.logResultLong(harness, transactionId1, transactionId2, data);
    }

    @Order(6)
    @JiraTestCase(id = "PAY-T2884")
    @TestCase(name = "HD:02 - Create Internal to Internal/External as Internal transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentInternalToExternalAsInternal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                                          @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.accExternalAsInternal1"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, ARCHIV);

        PaymentEngineUtils.logResultShort(harness, transactionId, data);
    }

    @Order(7)
    @JiraTestCase(id = "PAY-T2885")
    @TestCase(name = "HD:02 - Create Internal to Internal/External as External transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentAndVerify(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                       @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.accExternal1"));

        createAndVerifyTransactionWithPrefix(harness, user1, user2, ARCHIV);

        PaymentEngineUtils.logResultShortWithPrefix(harness, transactionId, data);
    }

    @Order(8)
    @JiraTestCase(id = "PAY-T2886")
    @TestCase(name = "HD:02 - Create External as Internal to Internal transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentExternalAsInternalToInternal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                                          @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.accExternalAsInternal1"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.creditorAccInt"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, ARCHIV);

        PaymentEngineUtils.logResultShort(harness, transactionId, data);
    }

    @Order(9)
    @JiraTestCase(id = "PAY-T2888")
    @TestCase(name = "HD:02 - Create External as Internal to External as Internal transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentExternalAsInternalToExternalAsInternal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                                                    @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.accExternalAsInternal1"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.accExternalAsInternal2"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, ARCHIV);

        PaymentEngineUtils.logResultShort(harness, transactionId, data);
    }

    @Order(10)
    @JiraTestCase(id = "PAY-T2889")
    @TestCase(name = "HD:02 - Create External as Internal to External transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentExternalAsInternalToExternal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                                          @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.accExternalAsInternal2"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.accExternal1"));

        createAndVerifyTransactionWithPrefix(harness, user1, user2, ARCHIV);

        PaymentEngineUtils.logResultShortWithPrefix(harness, transactionId, data);
    }

    @Order(11)
    @JiraTestCase(id = "PAY-T2882")
    @TestCase(name = "HD:02 - Create inhouse TIME transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentTimeToNormal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                          @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.accTime"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, INVALID_DEBTOR);
        String transactionId1 = transactionId;

        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.accTime"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, REJECT);
        String transactionId2 = transactionId;

        PaymentEngineUtils.logResultLong(harness, transactionId1, transactionId2, data);
    }

    @Order(12)
    @JiraTestCase(id = "PAY-T2883")
    @TestCase(name = "HD:02 - Create inhouse LOAN transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentLoanToNormal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                          @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.accLoan"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, INVALID_DEBTOR);
        String transactionId1 = transactionId;

        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.accLoan"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, REJECT);
        String transactionId2 = transactionId;

        PaymentEngineUtils.logResultLong(harness, transactionId1, transactionId2, data);
    }

    @Order(13)
    @JiraTestCase(id = "PAY-T2880")
    @TestCase(name = "HD:02 - Create inhouse Bankbook transaction and verify", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentBankbookToNormal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                              @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.accBankbook"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, INVALID_DEBTOR);
        String transactionId1 = transactionId;

        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.accBankbook"));

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, REJECT);
        String transactionId2 = transactionId;

        PaymentEngineUtils.logResultLong(harness, transactionId1, transactionId2, data);
    }

    @Order(14)
    @JiraTestCase(id = "PAY-T3000")
    @TestCase(name = "Change State Of Account From Active (1) To Closed (7)", environments = {Environment.TST1, Environment.PPE})
    void changeStateOfAccount(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.activeAccount"));

        changeClientsAccountState(harness, data.getDebtorAcc(), ACTIVE);

        checkAccountState(harness, user1, data, ACTIVE);

        changeClientsAccountState(harness, data.getDebtorAcc(), BLOCKED);

        checkAccountState(harness, user1, data, CLOSED_FOR_ENROLLMENT);

        changeClientsAccountState(harness, data.getDebtorAcc(), ACTIVE);

        harness.log("Account " + data.getDebtorAcc() + " state has been changed from " + ACTIVE.getState() + " to " + BLOCKED.getState() + " and back.");
        harness.store("reports.tmfj.execution.comment", "Account " + data.getDebtorAcc() + " state has been changed from " + ACTIVE.getState() + " to " + BLOCKED.getState() + " and back.");
    }

    @Order(15)
    @JiraTestCase(id = "PAY-T2879")
    @TestCase(name = "HD:02 - create Instant Payment New Opened (6) To Active (1)", environments = {Environment.TST1, Environment.PPE})
    void createInstantPaymentNewOpenedState6ToNormal(Harness harness, @Key(Keys.paymentEngine.firstUser) Credentials user1,
                                                     @Key(Keys.paymentEngine.secondUser) Credentials user2) {
        data.setDebtorAcc(harness.getConfig("payments_cashless.domesticPayment.newAccount"));
        data.setCreditorAcc(harness.getConfig("payments_cashless.domesticPayment.debtorAcc"));

        checkAccountState(harness, user1, data, ACTIVE);

        changeClientsAccountState(harness, data.getDebtorAcc(), CLOSED_FOR_ENROLLMENT);

        checkAccountState(harness, user1, data, TODAY_OPENED);

        createAndVerifyTransactionWithoutPrefix(harness, user1, user2, ARCHIV);

        changeClientsAccountState(harness, data.getDebtorAcc(), ACTIVE);

        checkAccountState(harness, user1, data, ACTIVE);

        PaymentEngineUtils.logResultShortWithAccountStateChange(harness, ACTIVE, TODAY_OPENED, transactionId, data);
    }

    private double parseValueGlobalStorePaymentEngine(String keyGlobalStorePaymentEngine) {
        String parsedAvailableBalance = keyGlobalStorePaymentEngine
                .replaceAll("\s", "")
                .replaceAll("\\.", "")
                .replaceAll(",", ".");
        return Double.parseDouble(parsedAvailableBalance);
    }
}
