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.NKK007_S001_ClipRequestPage.PAGE_ID_XPATH;

@Wait(value = PAGE_ID_XPATH, by = Lookup.XPATH)
public interface NKK007_S001_ClipRequestPage extends WebFlow<NKK007_S001_ClipRequestPage>, StoreAccessor {

    String PAGE_ID_XPATH = "//div[text()='NKK007_S001']";
    String CONTINUE_BUTTON = "NKK007_S001_B001";
    String NEW_AMOUNT_INPUT = "NKK007_S001_E006";
    String CURRENT_AMOUNT_LABEL = "NKK007_S001_L008";

    @Click(CONTINUE_BUTTON)
    NKK007_S001_ClipRequestPageTransitionPage clickContinueToTransitionPage();

    @CustomAction
    default NKK007_S001_ClipRequestPage getAndFillEditedHigherAmount() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String currentAmount = endpoint.getText(CURRENT_AMOUNT_LABEL);
        String editedAmount = currentAmount.replace(" ", "").replace(",00", "");
        Long higherEditedAmount = Long.parseLong(editedAmount) + 5000;
        endpoint.type(() -> NEW_AMOUNT_INPUT, higherEditedAmount.toString(), true);
        return null;
    }
}

