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 = "Change password")
public class ChangePasswordSettingsTest {
    Credentials clientCredentials;
    String clientId;

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

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

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

    @Order(1)
    @TestCase(name = "Change password in settings", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9333")
    public void changePasswordSettings(Harness harness) {
        String operIdPasswordChange= "10";
        String expectedStatusPasswordChange = "60";
        String channelId = "15";

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

        String statusPasswordChange = harness.withUdebs()
                .transactionsClient()
                .getLastTransactionStatus(clientId, operIdPasswordChange, channelId, 60, expectedStatusPasswordChange);

        harness.log("Expected status is: " + expectedStatusPasswordChange + " and status in UDEBS is: " + statusPasswordChange);
    }
}