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

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.KUL058_S002_ChangeCardFramePage.*;

@Wait(value = KUL058_S002_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 60)
public interface KUL058_S002_ChangeCardFramePage extends WebFlow<KUL058_S002_ChangeCardFramePage>, StoreAccessor {
    String KUL058_S002_PAGE_LABEL_XPATH = "//div[text()='KUL058_S002']";

    String CONTINUE_BUTTON = "KUL058_S002_B002";

    String REQUESTED_FRAME_INPUT = "KUL058_S002_E004";

    String ACTUAL_FRAME_LABEL = "KUL058_S002_L017";

    @TypeInto(REQUESTED_FRAME_INPUT)
    KUL058_S002_ChangeCardFramePage fillRequestedFrame(String requestedFrame);

    /**
     * For increase put positive number as parameter
     * For decrease put negative number as parameter
     */
    @CustomAction
    default KUL058_S002_ChangeCardFramePage changeActualFrameBy(int changeCardFrameBy) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String actualCardFrame = endpoint.getText(ACTUAL_FRAME_LABEL).replaceAll(" ", "");
        int cardFrameChange = Integer.parseInt(actualCardFrame) + changeCardFrameBy;

        endpoint.type(() -> REQUESTED_FRAME_INPUT, String.valueOf(cardFrameChange), false);
        endpoint.moveToElementAndClickToOtherElement(ACTUAL_FRAME_LABEL, ACTUAL_FRAME_LABEL);
        return null;
    }

    @Click(CONTINUE_BUTTON)
    KUL058_S002_ChangeCardFramePageTransitions clickContinue();
}
