package cz.moneta.test.regression.channels.digital.ib.newib.payment.fon;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.newib.tasks.NewIbTasks;
import cz.moneta.test.dsl.newib.util.PaymentFormData;
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 org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;

import java.text.DecimalFormat;
import java.time.LocalTime;
import java.util.concurrent.ThreadLocalRandom;

@TestScenarioWithOrder(name = "Foreign payment tests")
public class ForeignPaymentTest {

    Credentials clientCredentials;
    PaymentFormData formData;
    String generatedPaymentAmount;

    private String generateRandomPayment() {
        double doubleNumber = ThreadLocalRandom.current().nextDouble(1.00, 2.00);
        return new DecimalFormat("0.00").format(doubleNumber).replace(".", ",");
    }

    private String formatAccountNumber(String accountNumber) {
        return accountNumber.length() == 9 ? "0" + accountNumber : accountNumber;
    }

    @BeforeEach
    public void setup(Harness harness) {
        String clientBirthNumber = harness.getConfig("nib.rc.foreign-payment");
        String fromAccountNumber = harness.getConfig("nib.fromaccount.foreign-payment");
        String recipientAccountNumberEur = harness.getConfig("nib.recipientaccount.eur-currency");

        clientCredentials = harness.tasks()
                .udebs()
                .findCredentialsByRC(clientBirthNumber);

        formData = PaymentFormData.builder()
                .fromAccountNumber(fromAccountNumber)
                .recipientAccountNumber("BE62 5100 0754 7061")
                .currency("EUR")
                .typeOfCharge("SHA")
                .recipientName("Romelu Lukaku")
                .recipientAddressStreet("Greewek 1")
                .recipientAddressCity("Brusel")
                .recipientAddressCountry("BE - Belgie")
                .recipientMessage("Test message for recipient - foreign payment")
                .confirmationEmail("tomas.habinak@moneta.cz")
                .bankCountry("BE - Belgie")
                .bankCodeBic("VAPEBE22XXX")
                .bankNameAddress("VAN DE PUT AND CO PRIVATE BANKERS")
                .fromAccountType("Běžný účet CZK")
                .recipientAccountNumberEur(recipientAccountNumberEur)
                .bankCode("0600")
                .variableSymbol("111")
                .constantSymbol("2222")
                .specificSymbol("33333")
                .recipientBankAddressStreet("BANIYAS ROAD")
                .recipientBankCity("DUBAI")
                .validationCurrency("Zvolenou měnu banka nepřijímá, vyberte prosím jinou.")
                .alertCzIban("Zadali jste platbu v CZK na český IBAN. Proveďte platbu raději jako tuzemskou.")
                .errorIban("Toto pole je povinné.")
                .typeOfPayment("Prioritní ")
                .feeForeignPriorityPayment("500")
                .feeForeignPriorityPaymentSummary("500,00")
                .chargeBearerValue("SHA")
                .feeType("SHA")
                .estimatedAmountCurrency("GBP")
                .submitSourceCurrency("CZK")
                .conversionFeeCurrency("CZK")
                .paymentFeeCurrency("CZK")
                .changedRecipientAccountNumber("AT48 3200 0000 1234 58")
                .fees("BEN")
                .build();

        harness.tasks().wso2().client().subsidyCzkAccount(fromAccountNumber, 100);
    }

    @Order(1)
    @TestCase(name = "Foreign payment - happy path", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9198")
    public void foreignPayment(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payment is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.setForeignPaymentForm(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(2)
    @TestCase(name = "Domestic payment order – foreign (foreign currency) payment within MMB", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9189")
    public void domesticPaymentOrderForeignPaymentWithinMMB(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payment is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.setDomesticForeignPaymentForm(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(3)
    @TestCase(name = "Foreign payment - bank not accepting the given currency", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9235")
    public void foreignPaymentBankNotAcceptingTheGivenCurrency(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payment is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setCurrency("CZK");
        formData.setRecipientAccountNumber("AE870260000959062683901");
        formData.setBankCodeBic("EBILAEADXXX");
        formData.setBankNameAddress("EMIRATES NBD BANK PJSC");
        formData.setBankCountry("AE");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.foreignPaymentBankNotAcceptingTheGivenCurrency(formData));
    }

    @Order(4)
    @TestCase(name = "Foreign payment order - BIC check", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9229")
    public void bicContainsTheCountryOfTheRecipientBank(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setCurrency("USD");
        formData.setRecipientAccountNumber("CZ62 5100 0754 7061");
        formData.setBankCodeBic("IRVTUS3N");
        formData.setBankNameAddress("THE BANK OF NEW YORK MELLON");
        formData.setRecipientBankAddressStreet("240 GREENWICH STREET");
        formData.setRecipientBankCity("NEW YORK");
        formData.setBankCountry("US - USA");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.bicContainsTheCountryOfTheRecipientBank(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(5)
    @TestCase(name = "Foreign payment - CZK payment from CZK account to CZ bank", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9234")
    public void foreignCzkPaymentFromCzkAccountToCzBank(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setCurrency("CZK");
        formData.setRecipientAccountNumber("CZ55 0800 0000 0012 3456 7899");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.foreignCzkPaymentFromCzkAccountToCzBank(formData));
    }

    @Order(6)
    @TestCase(name = "Foreign payment - mandatory IBAN", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9230")
    public void foreignPaymentMandatoryIban(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setCurrency("USD");
        formData.setBankCodeBic("RIBLSARIXXX");
        formData.setBankNameAddress("RIYAD BANK");
        formData.setRecipientBankAddressStreet("A1 TOWER");
        formData.setRecipientBankCity("RIYADH");
        formData.setBankCountry("SA - Saúdská Arábie");
        formData.setRecipientAccountNumber("SA44 2000 0001 2345 6789 1234");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.foreignPaymentMandatoryIban(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(7)
    @TestCase(name = "Foreign order - priority foreign payment", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9222")
    public void priorityForeignPayment(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setCurrency("USD");
        formData.setRecipientAccountNumber("CZ62 5100 0754 7061");
        formData.setBankCodeBic("IRVTUS3N");
        formData.setBankNameAddress("THE BANK OF NEW YORK MELLON");
        formData.setRecipientBankAddressStreet("240 GREENWICH STREET");
        formData.setRecipientBankCity("NEW YORK");
        formData.setBankCountry("US - USA");

        Assumptions.assumeTrue(LocalTime.now().isBefore(LocalTime.of(13, 30)),
                "Skipped: Because COT is 13:30 and it's after 13:30");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.priorityForeignPayment(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(8)
    @TestCase(name = "Foreign payment - SEPA confirmation", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9225")
    public void sepaConfirmation(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.sepaConfirmation(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(9)
    @TestCase(name = "Foreign payment - foreign order confirmation", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9224")
    public void foreignOrderConfirmation(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setCurrency("USD");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.foreignOrderConfirmation(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(10)
    @TestCase(name = "Foreign order - priority SEPA payment", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9223")
    public void prioritySepaPayment(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setCurrency("EUR");
        formData.setRecipientAccountNumber("AT48 3200 0000 1234 5864");
        formData.setBankCodeBic("RLNWATWWXXX");
        formData.setBankNameAddress("RAIFFEISENLANDESBANK NIEDEROESTERRE");
        formData.setRecipientBankAddressStreet("Friedrich-Wilhelm-Raiffeisenplatz 1");
        formData.setRecipientBankCity("VIENNA");
        formData.setBankCountry("AT - Rakousko");
        formData.setFeeForeignPriorityPayment("0");
        formData.setFeeForeignPriorityPaymentSummary("0,00");

        Assumptions.assumeTrue(LocalTime.now().isBefore(LocalTime.of(13, 0)),
                "Skipped: Because COT is 13:00 and it's after 13:00");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.prioritySepaPayment(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(11)
    @TestCase(name = "Foreign payment - fee calcucator, exchange rate difference", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9232")
    public void foreignPaymentFeeCalculatorAndExchangeRateDifference(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setCurrency("GBP");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.foreignPaymentFeeCalculatorAndExchangeRateDifference(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
}

    @Order(12)
    @TestCase(name = "SEPA payment - fee calcucator, exchange rate difference", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9233")
    public void sepaPaymentFeeCalculatorAndExchangeRateDifference(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setRecipientAccountNumber("AT48 3200 0000 1234 5864");
        formData.setEstimatedAmountCurrency("EUR");
        formData.setBankCodeBic("RLNWATWWXXX");
        formData.setBankNameAddress("RAIFFEISENLANDESBANK NIEDEROESTERRE");
        formData.setRecipientBankAddressStreet("Friedrich-Wilhelm-Raiffeisenplatz 1");
        formData.setRecipientBankCity("VIENNA");
        formData.setBankCountry("AT - Rakousko");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.sepaPaymentFeeCalculatorAndExchangeRateDifference(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(13)
    @TestCase(name = "SEPA payment - mandatory IBAN to countries in the IBAN code list", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9231")
    public void sepaPaymentMandatoryIbanToCountriesInTheIbanCodeList(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setBankCodeBic("SOGEDEFFXXX");
        formData.setBankNameAddress("SOCIETE GENERALE S.A.");
        formData.setRecipientBankAddressStreet("NEUE MAINZER STRASSE 46-50");
        formData.setRecipientBankCity("FRANKFURT AM MAIN");
        formData.setBankCountry("DE - Německo");
        formData.setRecipientAccountNumber("DE75 5121 0800 1245 1261 99");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.sepaPaymentMandatoryIbanToCountriesInTheIbanCodeList(formData))
                .then(newIbTasks.checkSummaryForeignPaymentPageAndConfirmWithMobileKey(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(14)
    @TestCase(name = "Foreign payment - all currencies within the EEA with SHA fee only", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9228")
    public void foreignPaymentAllCurrenciesWithinTheEeaWithShaFeeOnly(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setRecipientAccountNumber("AT48 3200 0000 1234 5864");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.foreignPaymentAllCurrenciesWithinTheEeaWithShaFeeOnly(formData));
    }

    @Order(15)
    @TestCase(name = "Foreign payment - all currencies outside the EEA with any fee", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9227")
    public void foreignPaymentAllCurrenciesOutsideTheEeaWithAnyFee(Harness harness) {
        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setAmount(generatedPaymentAmount);
        formData.setRecipientAccountNumber("US64 SVBK US6S 3300 9588");
        formData.setBankCodeBic("IRVTUS3NXXX");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.foreignPaymentAllCurrenciesOutsideTheEeaWithAnyFee(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }

    @Order(16)
    @TestCase(name = "Foreign payment - payment status in case of NSF", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9226")
    public void foreignPaymentPaymentStatusInCaseOfNsf(Harness harness) {
        String clientBirthNumber = harness.getConfig("nib.rc.foreign-overdraft-payment");
        String fromAccountNumber = harness.getConfig("nib.fromaccount.foreign-overdraft-payment");

        clientCredentials = harness.tasks()
                .udebs()
                .findCredentialsByRC(clientBirthNumber);

        generatedPaymentAmount = generateRandomPayment();
        harness.log("Generated amount for foreign payments is: " + generatedPaymentAmount);
        NewIbTasks newIbTasks = harness.tasks().newIb();
        formData.setFromAccountNumber(fromAccountNumber);
        formData.setAmount(generatedPaymentAmount);
        formData.setRecipientAccountNumber("DE75 5121 0800 1245 1261 99");
        formData.setBankCodeBic("SOGEDEFFXXX");
        formData.setBankNameAddress("SOCIETE GENERALE S.A.");
        formData.setRecipientBankAddressStreet("NEUE MAINZER STRASSE 46-50");
        formData.setRecipientBankCity("HESSEN");
        formData.setBankCountry("DE - Německo");

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.foreignPaymentPaymentStatusInCaseOfNsfEur(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount)
                .clickOnOverviewButton()
                .then(newIbTasks.foreignPaymentPaymentStatusInCaseOfNsfCad(formData))
                .clickOnTransactionOverview()
                .onHistoryTabs()
                .checkTransaction(formData.getRecipientAccountNumber(), "-" + generatedPaymentAmount);

        double actual = harness.withUdebs()
                .paymentOrder()
                .getAmountOfLastForeignPaymentOrder(5, formatAccountNumber(formData.getFromAccountNumber()));

        double expected = Double.parseDouble(generatedPaymentAmount.replace(",", "."));

        Assertions.assertEquals(expected, actual, "Foreign payment amount entered in IB was " + generatedPaymentAmount + " but last amount in udebs is " + actual);
        harness.log("Generated payment is:" + generatedPaymentAmount + " and amount in UDEBS is: " + actual);
    }
}