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.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 static cz.moneta.test.dsl.exevido.pages.NewIncomingMessagePage.MESSAGE_ID_KEY;
import static cz.moneta.test.dsl.exevido.pages.NewOutgoingMessagePage.ATTACHMENT_PATH;
import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;

@TestScenario(name = "Return Of The Message To The Mailroom")
class ReturnOfTheMessageToTheMailroom {

    @TestCase(name = "Return Of The Message To The Mailroom")
    @JiraTestCase(id = "BOC-T8949")
    public void returnOfTheMessageToTheMailroom(Harness harness, @Key(Keys.exevido.inheritance) Credentials inheritance, @Key(Keys.exevido.mailroom) Credentials mailroom) {
        harness.withExevido()
                .openLoginPage()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(mailroom))
                .clickIncomingMessages()
                .clickCreateNewIncomingMessage()
                .fillSubject("Vrácení na podatelnu - dědictví")
                .fillSender("5nqh2a3")
                .fillTypeMessage("Obecná - MMB")
                .uploadAttachment(ATTACHMENT_PATH)
                .fillAssigneeUserGroup("05 - Dědictví")
                .clickSave()
                .storeMessageId()
                .logOutFromExevido()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(inheritance))
                .clickIncomingMessages()
                .clickIncomingMessages()
                .clickAllIncomingMessages()
                .searchByMessageId(harness.get(MESSAGE_ID_KEY))
                .clickIncomingMessageRow(30)
                .clickReturn()
                .fillReason("DĚD 7 TEST")
                .clickAddReason()
                .checkMessageReturn("Zpráva byla vrácena na podatelnu k dalšímu zpracování");
    }

    @AfterEach
    protected void tearDown(Harness harness) {
        harness.store(JIRA_COMMENT_STORE_KEY,
                "\nMessage ID: " + harness.get(MESSAGE_ID_KEY, true));
    }
}