package cz.moneta.test.dsl.ufo.banka.pages.loans;

import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.support.web.*;

@Wait(value = {VER017_S001_SecondBankerVerificationStatusPage.VER017_S001_PAGE_LABEL_XPATH}, waitSecondsForElement = 30, by = Lookup.XPATH)
public interface VER017_S001_SecondBankerVerificationStatusPage extends WebFlow<VER017_S001_SecondBankerVerificationStatusPage>, StoreAccessor {
    String VER017_S001_PAGE_LABEL_XPATH = "//div[text()='VER017_S001']";
    String APPLICATION_ID_KEY = "APPLICATION_ID";
    String APPLICATION_STATUS_LABEL = "VER017_S001_L041";
    String APPLICATION_STATUS_XPATH = "//div[@id='VER017_S001_L041' and text()='%s']";
    String RELOAD_BUTTON = "VER017_S001_B007";
    String CONTINUE_BUTTON = "VER017_S001_B005";
    String APPLICATION_ID_DIV = "VER017_S001_L003";

    @CheckElementContent(APPLICATION_STATUS_LABEL)
    VER017_S001_SecondBankerVerificationStatusPage checkVerificationStatus(String expectedStatus);

    @Click(value = RELOAD_BUTTON, andWait = @Wait(value = CONTINUE_BUTTON, until = Until.CLICKABLE))
    VER017_S001_SecondBankerVerificationStatusPage clickReload();

    @StoreElementContent(storeKey = APPLICATION_ID_KEY, value = APPLICATION_ID_DIV)
    VER017_S001_SecondBankerVerificationStatusPage storeApplicationId();

    @CustomAction
    default VER017_S001_SecondBankerVerificationStatusPage waitForStatus(String status) {

        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String xpath = String.format(APPLICATION_STATUS_XPATH, status);
        endpoint.waitForElementAndRefresh(xpath, RELOAD_BUTTON, Lookup.XPATH, Lookup.ID, 30, 5);
        return null;
    }

    @Click(CONTINUE_BUTTON)
    VER017_S001_SecondBankerVerificationStatusPageTransitions clickContinue();
}
