package cz.moneta.test.regression.commercial.cb;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks;
import cz.moneta.test.harness.annotations.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Order;

import static cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage.FULL_NAME_KEY;
import static cz.moneta.test.dsl.ufo.cb.landing.AUT402_S001_KOCriteriaListPage.UFO_SECOND_WINDOW_SESSION_ID_KEY;
import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;

@TestScenarioWithOrder(name = "Loading KO Criteria")
public class LoadingKOCriteria {

    private String clientIco;

    @TestCase(name = "Loading KO Criteria FOP", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T2114")
    @Order(1)
    public void loadingKOCriteriaFop(Harness harness) {

        loadingKOCriteria(harness, harness.getConfig("commercial.cb.ico.fop"));
    }

    @TestCase(name = "Loading KO Criteria PO", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T2137")
    @Order(2)
    public void loadingKOCriteriaPo(Harness harness) {

        loadingKOCriteria(harness, harness.getConfig("commercial.cb.ico.po"));
    }

    private void loadingKOCriteria(Harness harness, String ico) {
        clientIco = ico;
        CommercialTasks commercialTasks = harness.tasks().ufo().cb();
        harness.withUfo()
                .openLoginPage()
                .then(commercialTasks.loginAsCbBanker())
                .then(commercialTasks.searchClient(clientIco))
                .storeClientFullName()
                .clickKOCriteria()
                .switchToOtherWindow()
                .then(commercialTasks.checkKOCriteriaCalculation());
    }

    @AfterEach
    protected void teardown(Harness harness) {
        harness.store(JIRA_COMMENT_STORE_KEY,
                "\nIČO klienta: " + clientIco +
                        "\nJméno klienta: " + harness.get(FULL_NAME_KEY, true) +
                        "\nUFO Session ID: " + harness.get("reports.tmfj.execution.commentufosessionid", true) +
                        "\nUFO Session ID second window: " + harness.get(UFO_SECOND_WINDOW_SESSION_ID_KEY, true));
    }
}
