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.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;

@TestScenarioWithOrder(name = "Client Involvement")
public class ClientInvolvement {

    private String clientIco;

    @TestCase(name = "Client Involvement FOP", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T2113")
    @Order(1)
    public void clientInvolvementFop(Harness harness) {

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

    @TestCase(name = "Client Involvement PO", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SC-T2136")
    @Order(2)
    public void clientInvolvementPo(Harness harness) {

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

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

    @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));
    }
}
