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 static cz.moneta.test.dsl.exevido.pages.NewIncomingMessagePage.INCOMING_MESSAGE_ID_KEY;

@TestScenario(name = "Reassign Document")
public class ReassignDocument {

    @TestCase(name = "Reassign Document")
    @JiraTestCase(id = "BOC-T8950")
    public void reassignDocument(Harness harness, @Key(Keys.exevido.inheritance) Credentials credentials) {
        String subjectForReassignDocument = harness.getConfig("commercial.exevido.subject-for-reassign-document");
        String attachmentForReassignDocument = harness.getConfig("commercial.exevido.attachment-for-reassign-document");
        String internalReferenceNumberReassignDocument = harness.getConfig("commercial.exevido.internal-reference-number-for-reassign-document");
        String folderIssueNumber = harness.getConfig("commercial.exevido.folder-issue-number");

        harness.withExevido()
                .openLoginPage()
                .then(harness.tasks().exevidoTasks().login().withCredentialsToMmb(credentials))
                .clickIncomingMessages()
                .then(harness.tasks().exevidoTasks().createNewIncomingMessageTasks().forInheritance(subjectForReassignDocument, "Axis Ostrava", attachmentForReassignDocument))
                .clickInheritanceMmbForProcessing()
                .clickRequestMmb()
                .searchByMessageId(harness.get(INCOMING_MESSAGE_ID_KEY))
                .clickIncomingMessageRow(30)
                .checkInternalReferenceNumber(internalReferenceNumberReassignDocument)
                .clickInheritanceMmbFolders()
                .fillProductOwnerName(subjectForReassignDocument)
                .clickFolderRow()
                .openMessageById(harness.get(INCOMING_MESSAGE_ID_KEY))
                .clickAddMessageFolder()
                .fillFolderIssueNumber(folderIssueNumber)
                .saveFolderIssueNumber()
                .removeFolderIssueNumber(internalReferenceNumberReassignDocument);
    }
}