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.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 = "Cards")
public class CardsSettingsTest {

    Credentials clientCredentials;
    String clientId;

    @BeforeAll
    public void getCredentials(Harness harness) {
        String clientBirthNumber = harness.getConfig("nib.rc.settings.cards.fon");

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

        clientId = harness.withUdebs()
                .usersTable()
                .getClientId(clientBirthNumber);
    }

    @Order(1)
    @TestCase(name = "Debit cards - detail and adjusting settings", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9740")
    public void cardsSettingsTest(Harness harness) {

        NewIbTasks newIbTasks = harness.tasks().newIb();
        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.cardsSettingsTest());
    }

    @Order(2)
    @TestCase(name = "Debit cards - temporary blocking and unblocking", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9741")
    public void cardsSettingsTemporaryBlockingTest(Harness harness) {

        NewIbTasks newIbTasks = harness.tasks().newIb();
        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.cardsSettingsTemporaryBlockingTest());
    }

    @Order(3)
    @TestCase(name = "Credit cards - detail", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9839")
    public void creditCardsSettingsTest(Harness harness) {
        String clientBirthNumber = harness.getConfig("nib.rc.settings.creditCards.fon");

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

        NewIbTasks newIbTasks = harness.tasks().newIb();
        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.creditCardsSettingsTest());
    }
}