package cz.moneta.test.dsl.kasanova;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.kasanova.authentication.KSNLoginPage;
import cz.moneta.test.harness.endpoints.kasanova.KasanovaEndpoint;
import cz.moneta.test.harness.support.web.Builders;
import cz.moneta.test.harness.support.web.Until;

public class Kasanova {

    public static final String MAIN_FRAME = "framemain";
    public static final String CONTINUE_BUTTON = "continuebut";
    private final Harness harness;

    public Kasanova(Harness harness) {
        this.harness = harness;
    }

    public KSNLoginPage openLoginPage() {
        KasanovaEndpoint endpoint = harness.getEndpoint(KasanovaEndpoint.class);
        endpoint.openApplication();
        endpoint.switchToFrame(MAIN_FRAME);
        endpoint.waitForElementsToLoad(20, Until.PRESENT_IN_DOM, CONTINUE_BUTTON);
        endpoint.click(() -> CONTINUE_BUTTON);
        return Builders.newWebFlowBuilder(KSNLoginPage.class, endpoint, harness);
    }

    public boolean isStornoOn() {
        return Boolean.parseBoolean(this.harness.getConfig("kasanova-config.doStorno"));
    }

}
