package cz.moneta.test.dsl.exevido;

import cz.moneta.test.dsl.exevido.components.ExevidoPanels;
import cz.moneta.test.harness.endpoints.WebEndpoint;
import cz.moneta.test.harness.support.web.Builder;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.WebFlow;

import java.util.function.UnaryOperator;

public interface ExevidoWebFlow<A extends ExevidoWebFlow<A>> extends WebFlow<A>, ExevidoPanels<A>, Builder {

    void beforePageLoad(WebEndpoint endpoint);

    /**
     * Executes steps that starts and ends on the same page type that is not known in advance.
     * <p>
     * This method exists alongside the {@link Builder#then(java.util.function.Function)}
     * to explicitly model steps where {@code S == T} and where S and T are not known in advance.
     *
     * This is annotated with {@code @CustomAction} so that the Harness's invocation pipeline treats it
     * as an executable step and actually invokes the default method on the proxy.
     *
     * @param steps the flow of steps to be applied to the current page proxy
     * @return the same page proxy type {@code A} to allow fluent chaining
     */
    @SuppressWarnings("unchecked")
    @CustomAction
    default A thenSame(UnaryOperator<A> steps) {
        return steps.apply((A) this);
    }

}