package cz.moneta.test.dsl.testautomationpage;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.testautomationpage.TestAutomationPageEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.testautomationpage.TestAutomationPageHome.MAIN_TITLE;

@Wait(MAIN_TITLE)
public interface TestAutomationPageHome extends WebFlow<TestAutomationPageHome>, StoreAccessor {
    String MAIN_TITLE = "//h1[@id='mainTitle']";
    String COMBOBOX = "//select[@id='combobox']";
    String TEXTFIELD = "//input[@id='textfield']";
    String CHECKBOX = "//input[@id='checkbox']";
    String SUBMIT_BUTTON = "//input[@value='Test button']";
    String STORE_KEY = "TEST_AUTOMATION_PAGE_KEY";

    @AcceptAlert(waitSecondsForAlert = 10, expectedAlertText = "Test alert")
    TestAutomationPageHome acceptAlert();

    @Click(CHECKBOX)
    TestAutomationPageHome checkCheckbox();

    @Click(SUBMIT_BUTTON)
    TestAutomationPageHome clickSubmitButton();

    @CustomAction
    default TestAutomationPageHome customAction() {
        TestAutomationPageEndpoint endpoint = getEndpoint(TestAutomationPageEndpoint.class);
        endpoint.sleepSeconds(1);
        endpoint.scrollIntoView(SUBMIT_BUTTON);
        return null;
    }

    @DismissAlert(waitSecondsForAlert = 10, expectedAlertText = "Test alert")
    TestAutomationPageHome dismissAlert();

    @ExecuteJavaScript("alert('Test alert');")
    TestAutomationPageHome executeJavaScript();

    @CheckElementContent(MAIN_TITLE)
    TestAutomationPageHome checkElementContent(String content);

    @CheckElementPresent(COMBOBOX)
    TestAutomationPageHome checkElementPresent();

    @KeyPress(Key.TAB)
    TestAutomationPageHome keyPressTab();

    @Log(value = MAIN_TITLE, template = "Header of page is: {}")
    TestAutomationPageHome log();

    @Select(COMBOBOX)
    TestAutomationPageHome selectCombobox(String input);

    @StoreElementContent(storeKey = STORE_KEY, value = MAIN_TITLE)
    TestAutomationPageHome storeElementContent();

    @TypeInto(TEXTFIELD)
    TestAutomationPageHome typeIntoTextfield(String input);
}