package cz.moneta.test.dsl.ufo.banka.pages.cards.debit;

import cz.moneta.test.dsl.Harness;
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.cards.credit.OPN008_S001_SignContractPage.APPLICATION_ID_KEY;
import static cz.moneta.test.dsl.ufo.banka.pages.cards.debit.OBR003_S001_ClientContractSignPage.PAGE_LABEL_XPATH;

@Wait(value = PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 150)
public interface OBR003_S001_ClientContractSignPage extends WebFlow<OBR003_S001_ClientContractSignPage>, StoreAccessor {

    String PAGE_LABEL_XPATH = "//div[text()='OBR003_S001']";
    String LEFT_BUTTON = "OBR003_S001_B001";
    String CENTER_BUTTON = "OBR003_S001_B002";
    String RIGHT_BUTTON = "OBR003_S001_B003";
    String ICO_INPUT = "OBR003_S001_E001";
    String PAGE_VERIFICATION_SUCCESSFUL_LABEL_XPATH = "//div[text()='Verifikace proběhla úspěšně']";
    String PRODUCTS_SUCCESSFULY_ESTABLISHED_LABEL_XPATH = "//div[text()='Produkty byly úspěšně založeny']";
    String APPLICATION_ID_DIV = "OBR003_S001_L002";

    @Click(CENTER_BUTTON)
    OBR003_S001_ClientContractSignPageTransitions clickCenterButton();

    @Click(LEFT_BUTTON)
    OBR003_S001_ClientContractSignPageTransitions clickLeftButton();

    @Click(RIGHT_BUTTON)
    OBR003_S001_ClientContractSignPageTransitions clickRightButton();

    @TypeInto(value = ICO_INPUT)
    OBR003_S001_ClientContractSignPage fillIco(String ico);

    @CheckElementPresent(value = PAGE_VERIFICATION_SUCCESSFUL_LABEL_XPATH, by = Lookup.XPATH)
    OBR003_S001_ClientContractSignPage checkSuccessfulVerification();

    @CheckElementPresent(value = PRODUCTS_SUCCESSFULY_ESTABLISHED_LABEL_XPATH, by = Lookup.XPATH)
    OBR003_S001_ClientContractSignPage checkSuccessfulyEstablishedProducts();

    @CustomAction
    default OBR003_S001_ClientContractSignPage storeApplicationId(Harness harness) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String applicationID = endpoint.getText(APPLICATION_ID_DIV);
        harness.store(APPLICATION_ID_KEY, applicationID.split(" ")[2]);
        return null;
    }
}
