package cz.moneta.test.regression.backoffice.exevido.web.inheritance;

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.UploadUtil.getResourcePath;
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 = "Create Task And Check In Exevido")
class CreateTaskAndCheckInExevido {

    private OperationsTasks operationsTasksTasks;
    private String deathCertificateName;
    private String deathCertificateAttachment;
    private String birthNumber;

    @BeforeAll
    protected void setUp(Harness harness) {
        deathCertificateName = harness.getConfig("commercial.exevido.death-certificate-name");
        deathCertificateAttachment = harness.getConfig("commercial.exevido.death-certificate-attachment");
        birthNumber = harness.getConfig("commercial.exevido.birth-number");
    }

    @TestCase(name = "Resolution", environments = {PPE, TST1})
    @JiraTestCase(id = "BOC-T8965")
    public void resolution(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentialsUfo, @Key(Keys.exevido.inheritance) Credentials credentialsExevido) {
        operationsTasksTasks = harness.tasks().ufo().operations();
        String attachmentTitle = "Usnesení " + deathCertificateName;
        String attachmentPath = getResourcePath(deathCertificateAttachment);

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentialsUfo))
                .clickTasks()
                .clickNewMainTask()
                .selectTaskCategory("Klient")
                .selectSubcategories("Dědictví")
                .selectTaskType("Usnesení")
                .fillBirthNumberInTask(birthNumber)
                .fillIdOmInTask("02122120")
                .selectReporterTeam("OCS Dědictví")
                .then(operationsTasksTasks.tasks().checkAttachmentUpload("Doklad o dědictví", attachmentPath, attachmentTitle))
                .fillDescription("usnesení")
                .clickAssign()
                .onTaskList()
                .assertStatusLabel("Úkol byl korektně přiřazen!")
                .saveTaskID();

        harness.withExevido()
                .openLoginPage()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(credentialsExevido))
                .clickAllIncomingMessages()
                .searchByMessageId(harness.get(TASK_ID_KEY))
                .verifyIncomingMessageRowNotPresent();
    }

    @AfterEach
    protected void tearDown(Harness harness) {
        harness.store(JIRA_COMMENT_STORE_KEY,
                "\nID Úkolu: " + harness.get(TASK_ID_KEY, true));

    }

}