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

import cz.moneta.test.dsl.Harness;
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.ufoOperations.UKO720_S001_TaskList.TASK_ID_KEY;
import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;

@TestScenario(name = "Cancel Task")
public class CancelTask {

    private OperationsTasks operationsTasksTasks;
    private String rcOfExistingClient;

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

    @TestCase(name = "Cancel Task", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "BOC-T8405")
    public void cancelTask(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .clickTasks()
                .then(operationsTasksTasks.tasks().createSimpleTask(rcOfExistingClient))
                .saveTaskID()
                .fillTaskID(harness.get(TASK_ID_KEY))
                .clickFind()
                .clickOpenTaskDetail()
                .clickCancellation()
                .fillNote("Storno úkolu")
                .clickOkCancellation();
    }

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

}
