package cz.moneta.test.dsl.ufo.operations.ufoOperations;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
import cz.moneta.test.dsl.ufo.operations.shared.topmenu.XXX702_SharedTopMenu;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;
import static cz.moneta.test.dsl.ufo.operations.ufoOperations.PSP701_S001_AmortizationPage.INNER_TAB_PSP701;

@Wait(value = INNER_TAB_PSP701, waitSecondsForElement = 30)
public interface PSP701_S001_AmortizationPage extends WebFlow<PSP701_S001_AmortizationPage>, XXX702_SharedTopMenu<PSP701_S001_AmortizationPage>, StoreAccessor {
    String INNER_TAB_PSP701 = "PSP701_S004_I001_innerTab";
    String AMORTIZATION_DETAIL_LABEL = "PSP701_S004_L002";

    String BACK_DART_BUTTON = "PSP701_S004_P006";
    String IB_SB_CHECKBOX = "PSP701_S004_H001_IBSB";

    String SEND_BUTTON = "PSP701_S004_B003";
    String EMAIL_CHECKBOX = "PSP701_S004_H001_EMAIL";
    String SAVE_TO_ETS_BUTTON = "PSP701_S004_H001_ETS";

    @CheckElementPresent(AMORTIZATION_DETAIL_LABEL)
    PSP701_S001_AmortizationPage assertAmortizationLabel();

    @CheckElementContent(AMORTIZATION_DETAIL_LABEL)
    PSP701_S001_AmortizationPage checkAmortizationLabel(String text);

    @Click(BACK_DART_BUTTON)
    STS701_S002_ClientDetailPage clickBackButton();

    @Wait(value = SEND_BUTTON, until = Until.CLICKABLE)
    @Click(value = SEND_BUTTON)
    PSP701_S001_AmortizationPageTransitions clickSendButton();

    @Wait(value = IB_SB_CHECKBOX, until = Until.VISIBLE)
    @CustomAction
    default PSP701_S001_AmortizationPage checkIfIBSBIsChecked() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals("true", endpoint.getAttribute(IB_SB_CHECKBOX, "checked"), "The IB/SB isn't checked.");
        return null;
    }

    @CustomAction
    default PSP701_S001_AmortizationPage checkIfEmailCheckboxIsDisabled() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertFalse(endpoint.isElementEnabled(EMAIL_CHECKBOX), "Email checkbox is not disabled");
        return null;
    }

    @Click(value = SAVE_TO_ETS_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    PSP701_S001_AmortizationPage clickSaveToEts();
}