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

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.INCOMING_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 = "Delegating An Incoming Message")
public class DelegatingAnIncomingMessage {

    @TestCase(name = "Delegating An Incoming Message")
    @JiraTestCase(id = "BOC-T8500")
    public void delegatingAnIncomingMessage(Harness harness, @Key(Keys.exevido.mailroom) Credentials credentials) {
        harness.withExevido()
                .openLoginPage()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(credentials))
                .clickIncomingMessages()
                .clickCreateNewIncomingMessage()
                .fillSubject("Automat TEST - delegovaná")
                .fillSender("5nqh2a3 ")
                .fillTypeMessage("Obecná - MMB")
                .fillAssigneeUserGroup("800001 - IT")
                .uploadAttachment(ATTACHMENT_PATH)
                .clickSave()
                .acceptAlertIfVisible()
                .storeMessageId()
                .clickIncomingMessages()
                .clickAllIncomingMessages()
                .searchByMessageId(harness.get(INCOMING_MESSAGE_ID_KEY))
                .clickIncomingMessageRow(30)
                .fillAssignee("Adres")
                .clickDelegate()
                .clickIncomingMessageRow(30)
                .checkWarning("Tato zpráva je zpracovávána jiným uživatelem. Zpráva je zpracovávána uživatelem");
    }

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