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.*;
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.Order;

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;

@TestScenarioWithOrder(name = "Delegating An Incoming Message")
public class DelegatingAnIncomingMessage {

    @Order(1)
    @TestCase(name = "Delegation To Assignee")
    @JiraTestCase(id = "BOC-T9055")
    public void delegationToAssignee(Harness harness, @Key(Keys.exevido.inheritance) Credentials credentials) {
        harness.withExevido()
                .openLoginPage()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(credentials))
                .clickIncomingMessages()
                .then(harness.tasks().exevidoTasks().createNewIncomingMessageTasks().forInheritance("DĚD 10 - delegování", "Axis Ostrava", ATTACHMENT_PATH))
                .clickIncomingMessages()
                .clickAllIncomingMessages()
                .searchByMessageId(harness.get(INCOMING_MESSAGE_ID_KEY))
                .clickIncomingMessageRow(30)
                .fillAssignee("Simona Fošnárová")
                .clickDelegate()
                .clickIncomingMessageRow(30)
                .checkWarning("Tato zpráva je zpracovávána jiným uživatelem. Zpráva je zpracovávána uživatelem");
    }

    @Order(2)
    @TestCase(name = "Delegation To Group")
    @JiraTestCase(id = "BOC-T8953")
    public void delegatingToGroup(Harness harness, @Key(Keys.exevido.inheritance) Credentials credentials) {
        harness.withExevido()
                .openLoginPage()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(credentials))
                .clickIncomingMessages()
                .then(harness.tasks().exevidoTasks().createNewIncomingMessageTasks().forInheritance("DĚD 10 - delegování", "Axis Ostrava", ATTACHMENT_PATH))
                .clickIncomingMessages()
                .clickAllIncomingMessages()
                .searchByMessageId(harness.get(INCOMING_MESSAGE_ID_KEY))
                .clickIncomingMessageRow(30)
                .fillGroup("01 - Součinnosti")
                .clickDelegate();
    }

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