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.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.banka.pages.fon.DMS001_S001_ScanDocumentsPage.FAKE_ZL;
import static cz.moneta.test.dsl.ufo.banka.pages.fon.UploadUtil.getResourcePath;
import static cz.moneta.test.dsl.ufo.operations.ufoOperations.UKO720_S001_TaskList.SECOND_TASK_ID_KEY;
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;
import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Connecting Two Tasks")
public class ConnectingTwoTasks {

    private String rcOfExistingClient;

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

    @TestCase(name = "Connecting Two Tasks", environments = {PPE, TST1})
    @JiraTestCase(id = "BOC-T8506")
    public void connectingTwoTasks(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();
        String attachmentTitle = "Nazev prilohy pridane automatem";
        String attachmentPath = getResourcePath(FAKE_ZL);

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .clickTasks()
                .then(operationsTasksTasks.tasks().createSimpleTask(rcOfExistingClient))
                .clickNewMainTask()
                .selectTaskCategory("Ostatní - BPST")
                .selectSubcategories("Ostatní")
                .fillBirthNumberInTask(rcOfExistingClient)
                .selectTaskType("Ufo aplikace - podnět")
                .fillDescription("Test-2")
                .clickAssign()
                .onTaskList()
                .assertStatusLabel("Úkol byl korektně přiřazen!")
                .saveSecondTaskID()
                .fillTaskID(harness.get(TASK_ID_KEY))
                .clickFind()
                .clickOpenTaskDetail()
                .then(operationsTasksTasks.tasks().checkAttachmentUpload("Bankovní informace", attachmentPath, attachmentTitle))
                .fillIdTaskConnect(harness.get(SECOND_TASK_ID_KEY))
                .clickFirstAttachment()
                .clickConnectTasks()
                .clickHistory()
                .clickTaskChangeCheckbox()
                .fillReason("Automat test")
                .clickOkButton();

    }

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

}