package cz.moneta.test.regression.backoffice.ufooperations.jenkinstests;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.search.SearchBy;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.task.ufo.operations.OperationsTasks;
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.TestScenario;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;

import static cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage.CURRENT_ACCOUNT_NUMBER_KEY;
import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;

@TestScenario(name = "Current Account Loading And Check")
public class CurrentAccountLoadAndCheck {

    private String rcOfExistingClient;

    @BeforeAll
    protected void setUp(Harness harness) {
        rcOfExistingClient = harness.getConfig("ufo.operations.rc-of-existing-client");
    }

    @TestCase(name = "Current Account Loading Detail And Check", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "BOC-T8310")
    public void currentAccountLoadAndCheck(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .searchBy(SearchBy.BIRTH_NUMBER)
                .onClientDetailsPage()
                .storeAccountNumber()
                .clickAccountTree()
                .checkCurrentAccountNumber(harness.get(CURRENT_ACCOUNT_NUMBER_KEY));
    }

    @AfterEach
    protected void teardown(Harness harness) {
        harness.store(JIRA_COMMENT_STORE_KEY,
                "\nUFO Session ID: " + harness.get("reports.tmfj.execution.commentufosessionid"));
    }

}
