package cz.moneta.test.regression.channels.digital.ib.oldib;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.task.ib.IbTasks;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import cz.moneta.test.harness.support.auth.Credentials;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Order;

@TestScenarioWithOrder(name = "Create and delete a mail in IB")
public class IbMailTest {
    private Credentials credentials;
    private String mailSubject;
    private String mailMessage;

    @BeforeAll
    public void clientData(Harness harness) {
        String clientBirthNumber = harness.getConfig("IB.rc.message.user-with-SU");
        mailSubject = RandomStringUtils.randomAlphabetic(15);
        mailMessage = RandomStringUtils.randomAlphabetic(15);

        credentials = harness.withUdebs()
                .ib()
                .usernameAndPassword()
                .getUsernameAndPasswordByRc(clientBirthNumber);
    }

    @Disabled("Due to rewriting all IB regression tests")
    @Order(1)
    @TestCase(name = "Create a mail in IB")
    public void createMail(Harness harness) {
        IbTasks ibTasks = harness.tasks().ib();
        String mailTopic = "Účty";

        harness.withIB()
                .openLoginPage()
                .then(ibTasks.loginWithDefaultMobileKeyAnd(credentials))
                .messages()
                .clickOnWriteNewMail()
                .typeMailSubject(mailSubject)
                .selectMailTopic(mailTopic)
                .typeMailText(mailMessage)
                .clickOnSendMail()
                .checkInfoText()
                .clickOnSentMails()
                .openMail(mailSubject)
                .compareSentMailData(mailSubject, mailMessage);
    }

    @Disabled("Due to rewriting all IB regression tests")
    @Order(2)
    @TestCase(name = "Delete a mail in IB")
    public void deleteMail(Harness harness) {
        IbTasks ibTasks = harness.tasks().ib();

        harness.withIB()
                .openLoginPage()
                .then(ibTasks.loginWithDefaultMobileKeyAnd(credentials))
                .messages()
                .clickOnSentMails()
                .openMail(mailSubject)
                .compareSentMailData(mailSubject, mailMessage)
                .deleteMail()
                .checkDeletedMailInfoText();
    }
}
