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

@TestScenarioWithOrder(name = "Create Outgoing Message")
public class CreateNewOutgoingMessage {

    @Order(1)
    @TestCase(name = "Create Outgoing Message")
    @JiraTestCase(id = "BOC-T8316")
    public void createOutgoingMessage(Harness harness, @Key(Keys.exevido.mailroom) Credentials credentials) {
        harness.withExevido()
                .openLoginPage()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(credentials))
                .clickOutgoingMessages()
                .clickAllOutgoingMessages()
                .clickCreateNewOutgoingMessage()
                .fillRecipient("5nqh2a3")
                .uploadAttachment(ATTACHMENT_PATH)
                .fillSubject("Automat TEST")
                .fillAssigneeUserGroup("F00102")
                .clickSendMessageDropdown()
                .clickSendMessageNow()
                .checkMessageCorrectlySend()
                .storeMessageId();
    }

    @Order(2)
    @TestCase(name = "Create Outgoing Message With Failure")
    @JiraTestCase(id = "BOC-T8838")
    public void createOutgoingMessageWithFailure(Harness harness, @Key(Keys.exevido.mailroom) Credentials credentials) {
        harness.withExevido()
                .openLoginPage()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(credentials))
                .clickOutgoingMessages()
                .clickAllOutgoingMessages()
                .clickCreateNewOutgoingMessage()
                .fillRecipient(harness.getConfig("commercial.exevido.recipient-for-send-failure"))
                .uploadAttachment(ATTACHMENT_PATH)
                .fillSubject("Automat TEST")
                .fillAssigneeUserGroup("F00102")
                .clickSendMessageDropdown()
                .clickSendMessageNow()
                .checkMessageIncorrectlySend()
                .storeMessageId();
    }

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