package cz.moneta.test.dsl.util.task.ufo.operations;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.common.authentication.UfoLoginPage;
import cz.moneta.test.dsl.ufo.operations.error.ERR701_S001_LDAPErrorPage;
import cz.moneta.test.dsl.ufo.operations.search.OPS001_S001_ClientSearchPageUfoOperations;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.BOX701_DataBoxes;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.EXT701_S001_ExternalPartnersMainPage;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.businessSupport.ROZ702_S001_BusinessSupportMainPage;
import cz.moneta.test.harness.support.auth.AuthSupport;
import cz.moneta.test.harness.support.auth.Credentials;

import java.util.function.Function;

import static cz.moneta.test.dsl.util.credentials.Keys.ufo.banka.banker;

public final class LoginTasks {
    private final Harness harness;

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

    public Function<UfoLoginPage, OPS001_S001_ClientSearchPageUfoOperations> asBanker() {
        Credentials auth = AuthSupport.getCredentials(banker, harness);
        return start -> start.typeUserNameAndPasswordAndClickLogin(auth.getUsername(), auth.getPassword())
                .onApplicationSelectPage()
                .selectUfoOperationsAndContinueWithoutOmSelect();
    }

    public Function<UfoLoginPage, OPS001_S001_ClientSearchPageUfoOperations> withCredentials(Credentials credentials) {
        return start -> start.typeUserNameAndPasswordAndClickLogin(credentials.getUsername(), credentials.getPassword())
                .onApplicationSelectPage()
                .selectUfoOperationsAndContinueWithoutOmSelect();
    }

    public Function<UfoLoginPage, OPS001_S001_ClientSearchPageUfoOperations> withCredentialsAndSelectFirstOM(Credentials credentials) {
        return start -> start.typeUserNameAndPasswordAndClickLogin(credentials.getUsername(), credentials.getPassword())
                .onApplicationSelectPage()
                .selectOm(1)
                .selectUfoOperationsAndContinueWithoutOmSelect();
    }

    public Function<UfoLoginPage, OPS001_S001_ClientSearchPageUfoOperations> withCredentialsSelectHQ(Credentials credentials) {
        return start -> start.typeUserNameAndPasswordAndClickLogin(credentials.getUsername(), credentials.getPassword())
                .onApplicationSelectPage()
                .selectUfoOperationsAndHQContinue();
    }

    public Function<UfoLoginPage, EXT701_S001_ExternalPartnersMainPage> withCredentialsSelectExternalPartners(Credentials credentials) {
        return start -> start.typeUserNameAndPasswordAndClickLogin(credentials.getUsername(), credentials.getPassword())
                .onApplicationSelectPage()
                .selectExternalPartnersAndContinueWithoutOMSelect();
    }

    public Function<UfoLoginPage, ROZ702_S001_BusinessSupportMainPage> withCredentialsSelectBusinessSupport(Credentials credentials) {
        return start -> start.typeUserNameAndPasswordAndClickLogin(credentials.getUsername(), credentials.getPassword())
                .onApplicationSelectPage()
                .selectBusinessSupportAndContinueWithoutOmSelect();
    }

    public Function<UfoLoginPage, ERR701_S001_LDAPErrorPage> withCredentialsExpectingError(Credentials credentials) {
        return start -> start.typeUserNameAndPasswordAndClickLogin(credentials.getUsername(), credentials.getPassword())
                .onApplicationSelectPage()
                .selectUfoOperationsAndContinueToLDAPErrorPage();
    }

    public Function<UfoLoginPage, BOX701_DataBoxes> withCredentialsSelectDataboxes(Credentials credentials) {
        return start -> start.typeUserNameAndPasswordAndClickLogin(credentials.getUsername(), credentials.getPassword())
                .onApplicationSelectPage()
                .selectDataboxesAndContinueWithoutOmSelect();
    }

    public Function<UfoLoginPage, OPS001_S001_ClientSearchPageUfoOperations> withSecondBankerCredentials(Credentials credentials) {
        return start -> start.typeUserNameAndPasswordAndClickLogin(credentials.getUsername(), credentials.getPassword())
                .onClientSearchPageUfoOperations();
    }
}
