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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.shared.UfoOpsUtils;
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.BeforeAll;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.List;

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;

@TestScenario(name = "Create Financial Sheet On Clients")

public class CreateFinancialSheetOnClients {

    private String currentClientICO = null;
    String path;

    @BeforeAll
    public void setUp(Harness harness) {
        path = harness.getConfig("commercial.cb.ico-list-for-financial-sheet");
    }

    private List<String> returnValuesForTest() {
        return UfoOpsUtils.loadClientsIcoFromTextFile(path);
    }

    @ParameterizedTestCase(name = "Create Financial Sheets", environments = {Environment.TST1})
    @MethodSource("returnValuesForTest")
    @JiraTestCase(id = "SC-T2211")
    public void createFinancialSheets(String clientIco, Harness harness) {
        currentClientICO = clientIco;
        CommercialTasks commercialTasks = harness.tasks().ufo().cb();
        harness.withUfo().openLoginPage()
                .then(commercialTasks.loginAsCbContractualDocumentAdministrator())
                .then(commercialTasks.searchClient(clientIco))
                .clickFinancialSheets()
                .then(commercialTasks.createFinancialSheet());
    }

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