package cz.moneta.test.dsl.util.task.brokerportal;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.brokerportal.BrokerPortalHomePage;
import cz.moneta.test.dsl.brokerportal.BrokerPortalLoginPage;
import cz.moneta.test.harness.support.auth.Credentials;
import java.util.function.Function;

public class LoginTasks {

    private final Harness harness;

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

    public Function<BrokerPortalLoginPage, BrokerPortalHomePage> loginWithCredentials(Credentials credentials) {
        return start -> start
                .then(fillLoginWithCredentials(credentials.getUsername(), credentials.getPassword()))
                .clickLoginButton()
                .closeNewVersionModal();
    }

    public Function<BrokerPortalLoginPage, BrokerPortalLoginPage> loginWithBadCredentials(String username, String password) {
        return start -> start
                .then(fillLoginWithCredentials(username, password))
                .clickLoginStayOnLoginPageButton();
    }

    private Function<BrokerPortalLoginPage, BrokerPortalLoginPage> fillLoginWithCredentials(String username, String password) {
        return start -> start
                .fillLogin(username)
                .fillPassword(password);
    }
}