package cz.moneta.test.dsl.exevido.tasks;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.exevido.DataBoxType;
import cz.moneta.test.dsl.exevido.pages.IncomingMessagesPage;
import cz.moneta.test.dsl.exevido.pages.LoginPage;
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<LoginPage, IncomingMessagesPage> withCredentials(Credentials credentials) {
        return start -> start.fillUsername(credentials.getUsername())
                .fillPassword(credentials.getPassword())
                .clickLogin();
    }

    public Function<LoginPage, IncomingMessagesPage> withCredentialsToMmb(Credentials credentials) {
        return start -> start.then(withCredentials((credentials)))
                .thenSame(harness.tasks().exevidoTasks().selectDataBox().selectDataBoxMmbType(DataBoxType.MMB));
    }

    public Function<LoginPage, IncomingMessagesPage> withCredentialsToMss(Credentials credentials) {
        return start -> start.then(withCredentials((credentials)))
                .thenSame(harness.tasks().exevidoTasks().selectDataBox().selectDataBoxMssType(DataBoxType.MSS));
    }
}