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

import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
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.creditCard.NKK006_S001_CreditCardScoringResultPage.APP_ID_DIV;
import static cz.moneta.test.dsl.ufo.banka.pages.loans.creditCard.NKK006_S001_CreditCardScoringResultPage.APP_KEY_DIV;
import static cz.moneta.test.dsl.ufo.banka.pages.loans.creditCard.NKK006_S001_CreditCardScoringResultPage.NKK006_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 = NKK006_S001_PAGE_LABEL_XPATH, by = XPATH, waitSecondsForElement = 80)
@Wait(value = {APP_KEY_DIV, APP_ID_DIV}, waitSecondsForElement = 40)
public interface NKK006_S001_CreditCardScoringResultPage extends WebFlow<NKK006_S001_CreditCardScoringResultPage>, StoreAccessor {

    String NKK006_S001_PAGE_LABEL_XPATH = "//div[text()='NKK006_S001']";
    String APP_ID_DIV = "NKK006_S001_L027";
    String APP_ID_STORE = "APP_ID_STORE";
    String APP_KEY_DIV = "NKK006_S001_L030";
    String APP_KEY_STORE = "APP_KEY_STORE";
    String APP_STAT_DIV = "NKK006_S001_L015";
    String APP_STAT_STORE = "APP_STAT_STORE";
    String END_BUTTON = "NKK006_S001_B002";
    String REFRESH_BUTTON = "NKK006_S001_S001";
    String STATUS_GENERAL_XPATH = "//div[@id='NKK006_S001_L015' and contains(text(), '%s')]";
    String FOUNDATION_PRINT_CONTRACT_BUTTON = "NKK006_S001_B005";

    String CANCEL_BUTTON = "NKK006_S001_B006";

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

    @GetElementContent(APP_KEY_DIV)
    String getAppKey();

    @Log(value = APP_ID_DIV, template = "Client Credit Card Application ID is {}")
    @StoreElementContent(storeKey = APP_ID_STORE, value = APP_ID_DIV)
    NKK006_S001_CreditCardScoringResultPage storeAppId();

    @GetElementContent(APP_ID_DIV)
    String getAppId();

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

    @Click(END_BUTTON)
    HKO101_S001_MainClientPage clickEnd();

    @CustomAction
    default NKK006_S001_CreditCardScoringResultPage waitForStatusAndRefresh(String status) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementAndRefresh(String.format(STATUS_GENERAL_XPATH, status),
                REFRESH_BUTTON, XPATH, DEFAULT, 50, 15);
        return null;
    }

    @Click(FOUNDATION_PRINT_CONTRACT_BUTTON)
    NKK006_S001_CreditCardScoringResultPageTransitions clickCreateProductAndPrintContract();

    @Click(CANCEL_BUTTON)
    NKK006_S001_CreditCardScoringResultPageTransitions clickCancel();

    @Click(END_BUTTON)
    NKK006_S001_CreditCardScoringResultPageTransitions clickEndToClientRequestPage();
}
