package cz.moneta.test.dsl.ufo.banka.pages.products.universal.request;

import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.banka.pages.products.universal.request.UZO006_S001_UniverzalRequestModeling.PAGE_ID;

@Wait(value = PAGE_ID, waitSecondsForElement = 60)
public interface UZO006_S001_UniverzalRequestModeling extends WebFlow<UZO006_S001_UniverzalRequestModeling>, StoreAccessor, SharedElements {

    String PAGE_ID = "UZO006_S001_X001";
    String STORNO_BUTTON = "UZO006_S001_B006";
    String STATUS_GENERAL_XPATH = "//div[@id='UZO006_S001_L007' and contains(text(), '%s')]";
    String RELOAD_BUTTON = "UZO006_S001_S001";
    String END_BUTTON = "UZO006_S001_B002";
    String APPROVED_OFFERS_LIST_LABEL = "UZO006_S001_L008";
    String CALCULATOR_BUTTON = "UZO006_S001_B004";
    String APP_KEY_DIV = "UZO006_S001_L018";
    String APP_KEY_STORE = "APP_KEY_STORE";

    @CustomAction
    default UZO006_S001_UniverzalRequestModeling waitForStatusAndRefresh(String status) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementAndRefresh(String.format(STATUS_GENERAL_XPATH, status), RELOAD_BUTTON, Lookup.XPATH, Lookup.DEFAULT, 300, 10);
        endpoint.waitForElementsToLoad(10, Lookup.CLASSNAME, Until.GONE, LOAD_IMG_DIV_CLASS);
        return null;
    }

    @Click(END_BUTTON)
    UZO006_S001_UniverzalRequestModelingTransitions clickEndButton();

    @CheckElementPresent(APPROVED_OFFERS_LIST_LABEL)
    UZO006_S001_UniverzalRequestModeling checkApprovedOffersVisible();

    @Click(CALCULATOR_BUTTON)
    UZO006_S004_UniverzalRequestCombinationsCalculatorPage clickCalculator();

    @Click(STORNO_BUTTON)
    UZO006_S002_UniverzalStornoPage clickStorno();

    @StoreElementContent(storeKey = APP_KEY_STORE, value = APP_KEY_DIV)
    UZO006_S001_UniverzalRequestModeling storeAppKey();
}
