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

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.loans.flexikredit.NFL006_S001_FlexikreditScoringResultPage.APP_ID_DIV;
import static cz.moneta.test.dsl.ufo.banka.pages.loans.flexikredit.NFL006_S001_FlexikreditScoringResultPage.APP_KEY_DIV;
import static cz.moneta.test.dsl.ufo.banka.pages.loans.flexikredit.NFL006_S001_FlexikreditScoringResultPage.NFL006_S001_PAGE_LABEL_XPATH;
import static cz.moneta.test.harness.support.web.Lookup.DEFAULT;
import static cz.moneta.test.harness.support.web.Lookup.XPATH;

@Wait(value = NFL006_S001_PAGE_LABEL_XPATH, waitSecondsForElement = 60, by = XPATH)
@Wait(value = {APP_KEY_DIV, APP_ID_DIV}, waitSecondsForElement = 60)
public interface NFL006_S001_FlexikreditScoringResultPage extends WebFlow<NFL006_S001_FlexikreditScoringResultPage>, StoreAccessor, SharedElements, NFL006_S001_FlexikreditScoringResultPageTransitions {

    String NFL006_S001_PAGE_LABEL_XPATH = "//div[text()='NFL006_S001']";
    String APPROVED_TABLE_AMOUNT_KEY = "APPROVED_TABLE_AMOUNT";
    String APPROVED_TABLE_INTEREST_KEY = "APPROVED_TABLE_INTEREST";
    String APP_ID_DIV = "NFL006_S001_L030";
    String APP_ID_STORE = "APP_ID_STORE";
    String APP_KEY_DIV = "NFL006_S001_L018";
    String APP_KEY_STORE = "APP_KEY_STORE";
    String APP_STAT_DIV = "NFL006_S001_L015";
    String STATUS_GENERAL_XPATH = "//div[@id='NFL006_S001_L015' and contains(text(), '%s')]";
    String APP_STAT_STORE = "APP_STAT_STORE";
    String END_BUTTON = "NFL006_S001_B002";
    String RELOAD_BUTTON = "NFL006_S001_S001";
    String FOUNDATION_PRINT_CONTRACT_BUTTON = "NFL006_S001_B005";
    String APPROVED_TABLE_AMOUNT_XPATH = "//table[@id='NFL006_S001_G002_UfoTable']//tbody//td[1]";
    String APPROVED_TABLE_INTEREST_XPATH = "//table[@id='NFL006_S001_G002_UfoTable']//tbody//td[5]";

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

    @GetElementContent(APP_KEY_DIV)
    String getAppKey();

    @Log(value = APP_ID_DIV, template = "Client Flexikredit application ID is {}")
    @StoreElementContent(storeKey = APP_ID_STORE, value = APP_ID_DIV)
    NFL006_S001_FlexikreditScoringResultPage storeAppId();

    @GetElementContent(APP_ID_DIV)
    String getAppId();

    @StoreElementContent(storeKey = APP_STAT_STORE, value = APP_STAT_DIV)
    NFL006_S001_FlexikreditScoringResultPage storeAppStat();

    @CheckElementContent(APP_STAT_DIV)
    NFL006_S001_FlexikreditScoringResultPage checkApplicationState(String expectedState);

    @GetElementContent(APP_STAT_DIV)
    String getAppStat();

    @Click(END_BUTTON)
    NFL006_S001_FlexikreditScoringResultPageTransitions clickEnd();

    @Click(value = RELOAD_BUTTON,
            andWait = @Wait(value = {FOUNDATION_PRINT_CONTRACT_BUTTON}, until = Until.VISIBLE))
    NFL006_S001_FlexikreditScoringResultPage clickReloadButton();

    @Click(FOUNDATION_PRINT_CONTRACT_BUTTON)
    NFL006_S001_FlexikreditScoringResultPageTransitions clickFoundationPrintContractButton();

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

    @StoreElementContent(storeKey = APPROVED_TABLE_AMOUNT_KEY, value = APPROVED_TABLE_AMOUNT_XPATH, by = XPATH)
    NFL006_S001_FlexikreditScoringResultPage storeApprovedTableAmount();

    @StoreElementContent(storeKey = APPROVED_TABLE_INTEREST_KEY, value = APPROVED_TABLE_INTEREST_XPATH, by = XPATH)
    NFL006_S001_FlexikreditScoringResultPage storeApprovedTableInterest();

}
