package cz.moneta.test.dsl.ib.messages;

import cz.moneta.test.dsl.ib.IbPageFlow;
import cz.moneta.test.dsl.ib.components.MainMenu;
import cz.moneta.test.dsl.ib.components.UserMenu;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.IbEndpoint;
import cz.moneta.test.harness.support.web.AcceptAlert;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Wait;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.ib.messages.IbMailDetailPage.MAIL_DETAIL_TABLE;

@Wait(MAIL_DETAIL_TABLE)
public interface IbMailDetailPage extends IbPageFlow<IbMailDetailPage>, MainMenu, UserMenu, IbMailsLeftMenu, StoreAccessor {
    String MAIL_DETAIL_TABLE = "//table[contains(@id, 'mailDetail')]";
    String MAIL_SUBJECT = MAIL_DETAIL_TABLE + "//h3[@class = 'pageLabel']";
    String MAIL_MESSAGE = MAIL_DETAIL_TABLE + "//td[@class = 'message']";
    String DELETE_BTN = "//img[@alt = 'Smazat']";
    String DELETED_MAIL_TEX = "//div[text() = 'Zpráva byla smazána.']";

    @CustomAction
    default IbMailDetailPage compareSentMailData(String mailSubject, String mailMessage) {
        IbEndpoint endpoint = getEndpoint(IbEndpoint.class);
        String actualMailSubject = endpoint.getText(MAIL_SUBJECT);
        String actualMailMessage = endpoint.getText(MAIL_MESSAGE);
        Assertions.assertEquals(mailSubject, actualMailSubject, "Actual mail title " + actualMailSubject + " is not equal to expected " + mailSubject);
        Assertions.assertEquals(mailMessage, actualMailMessage, "Actual mail message " + actualMailMessage + " is not equal to expected " + mailMessage);
        return null;
    }

    @Wait(DELETE_BTN)
    @Click(DELETE_BTN)
    @AcceptAlert(waitSecondsForAlert = 20)
    IbMailDetailPage deleteMail();

    @Wait(DELETED_MAIL_TEX)
    IbMailDetailPage checkDeletedMailInfoText();

}
