package cz.moneta.test.regression.channels.digital.ib.newib.settings;

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.BeforeAll;
import org.junit.jupiter.api.Order;

@TestScenarioWithOrder(name = "Accounts settings tests")

public class AccountsSettingsTest {
    Credentials clientCredentials;
    String currentAccNumber;
    String currentAccIban;
    String savingsAccNumber;
    String savingsAccIban;

    @BeforeAll
    public void setup(Harness harness) {
        String clientBirthNumber = harness.getConfig("nib.rc.accounts-settings");
        currentAccNumber = harness.getConfig("nib.accountNumber.accounts-settings");
        currentAccIban = harness.getConfig("nib.iban.accounts-settings");
        savingsAccNumber = harness.getConfig("nib.savingsAccountNumber.accounts-settings");
        savingsAccIban = harness.getConfig("nib.iban.savingsAccount-settings");

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

    private PaymentFormData createFormData(String fromAccountType, String fromAccountNumber, String iban) {
        return PaymentFormData.builder()
                .fromAccountType(fromAccountType)
                .fromAccountNumber(fromAccountNumber)
                .iban(iban)
                .build();
    }

    @Order(1)
    @TestCase(name = "Check current account via settings", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9343")
    public void checkCurrentAccountSettings(Harness harness) {
        NewIbTasks newIbTasks = harness.tasks().newIb();

        PaymentFormData currentAccountData = createFormData("Gold", currentAccNumber, currentAccIban);

        String accountType = "currentAccounts";
        String accountTestName = "Current";

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.checkAccountsSettings(currentAccountData, accountType, accountTestName));
    }

    @Order(2)
    @TestCase(name = "Check savings account via settings", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9340")
    public void checkSavingsAccountSettings(Harness harness) {
        NewIbTasks newIbTasks = harness.tasks().newIb();

        PaymentFormData savingsAccountData = createFormData("SÚ Gold Plus", savingsAccNumber, savingsAccIban);

        String accountType = "savingsAccounts";
        String accountTestName = "Savings";

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.checkAccountsSettings(savingsAccountData, accountType, accountTestName));
    }
}