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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ib.account.saving.TransferOfFoundsEnteringPage;
import cz.moneta.test.dsl.ib.authentication.LoginPage;
import cz.moneta.test.dsl.ib.authentication.WelcomePageTransitions;
import cz.moneta.test.dsl.ib.tasks.cards.application.IbCardsApplicationTasks;
import cz.moneta.test.dsl.ib.welcome.WelcomePage;
import cz.moneta.test.harness.support.auth.Credentials;

import java.util.function.Function;

public final class IbTasks {

    private final Harness harness;

    public static String DEFAULT_MOBILE_KEY = "12341234";

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

    public Function<LoginPage, WelcomePageTransitions> loginWithUsernamePasswordAndMobileKey(String username, String password, String mobileKey) {
        return start -> start.typeUsername(username)
                .typePassword(password)
                .clickLogin()
                .onAuthMobileKeyPage()
                .fillMobileKey(mobileKey)
                .clickLogin();
    }

    public Function<LoginPage, WelcomePage> loginWith(Credentials credentials, String mobileKey) {
        return start -> (WelcomePage) start.typeUsername(credentials.getUsername())
                .typePassword(credentials.getPassword())
                .clickLogin()
                .onAuthMobileKeyPage()
                .fillMobileKey(mobileKey)
                .clickLogin()
                .onWelcomePage();
    }

    public Function<WelcomePage, TransferOfFoundsEnteringPage> transferOfFoundsSavingAccount() {
        return start -> start.getDispoSavingAccount()
                .getDispoCurrentAccount()
                .clickSavings()
                .clickToTransferOfFounds()
                .clickToChooseButton();
    }

    public Function<LoginPage, WelcomePage> loginWithDefaultMobileKeyAnd(Credentials credentials) {
        return loginWith(credentials, DEFAULT_MOBILE_KEY);
    }

    public IbCardsApplicationTasks cardsApplication() {
        return new IbCardsApplicationTasks();
    }

    public InsuranceIbTasks insuranceIbTasks() {
        return new InsuranceIbTasks(harness);
    }

    public IbContactDataTasks ibContactDataTasks() {
        return new IbContactDataTasks(harness);
    }

    public PaymentsIbTasks paymentsIbTasks() {
        return new PaymentsIbTasks(harness);
    }

    public DisponentsRightsIbTasks disponentsRightsIbTasks() {
        return new DisponentsRightsIbTasks(harness);
    }
}