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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.taskslist.TypesOfViewFilter;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.task.ufo.operations.OperationsTasks;
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 org.junit.jupiter.api.Disabled;

import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;
import static cz.moneta.test.harness.annotations.Environment.PPE;

@Disabled(value = "Used only for local runs")
@TestScenario(name = "Task List")
public class TaskList {

    private OperationsTasks operationsTasksTasks;

    @BeforeAll
    public void setUp(Harness harness) {
        operationsTasksTasks = harness.tasks().ufo().operations();
    }

    @TestCase(name = "Task List", environments = {PPE})
    @JiraTestCase(id = "BOC-T8816")
    public void taskList(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentialsAndSelectFirstOM(credentials))
                .clickTasks()
                .selectTypeOfView(TypesOfViewFilter.TEAM_TASKS)
                .clickOpenTaskDetail()
                .scrollToPageTop()
                .checkSolveButtonPresent()
                .clickTaskList()
                .selectTypeOfView(TypesOfViewFilter.MY_FOR_PROCESSING)
                .clickOpenTaskDetail()
                .scrollToPageTop()
                .checkSolveButtonPresent()
                .clickTaskList()
                .selectTypeOfView(TypesOfViewFilter.MY_FOR_VERIFICATION)
                .assertTaskStatus("Zpracovaný - neověřen")
                .selectTypeOfView(TypesOfViewFilter.PROCESSED_BY_ME)
                .assertTaskStatus("Zpracovaný")
                .clickOpenTaskDetail()
                .scrollToPageTop()
                .clickTaskList()
                .selectTypeOfView(TypesOfViewFilter.ASSIGNED_BY_ME)
                .assertTaskTaskmaster("Vlasáková Agáta")
                .checkRevitalizationButtonPresent()
                .selectTypeOfView(TypesOfViewFilter.TASK_SEARCH)
                .fillBirthNumber("8609209433")
                .clickFind()
                .assertTaskClientRc("8609209433")
                .checkRevitalizationButtonPresent()
                .clickReset()
                .fillIdObject("33214034")
                .clickFind()
                .assertTaskObjectId("33214034");
    }

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

}