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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.salesforce.pages.LoginPage;
import cz.moneta.test.dsl.salesforce.pages.MainPage;
import cz.moneta.test.dsl.salesforce.pages.accounts.AccountDetailPage;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.harness.support.auth.AuthSupport;
import cz.moneta.test.harness.support.auth.Credentials;

import java.util.function.Function;

public class SalesForceTasks {
    private final Harness harness;

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

    public NewOpportunityTasks newOpportunityTasks() {
        return new NewOpportunityTasks(harness);
    }

    public Function<LoginPage, MainPage> loginAsBanker() {
        Credentials credentials = AuthSupport.getCredentials(Keys.salesForce.banker, harness);
        return start -> start.loginWithUsernameAndPassword(credentials.getUsername(), credentials.getPassword())
                .onSalesForceMainPage();
    }

    public Function<MainPage, AccountDetailPage> openAccountDetail(String account) {
        return start -> start.searchItem(account)
                .clickAccountDetail(account)
                .onAccountDetailPage()
                .checkAccountId(account);
    }

    public Function<AccountDetailPage, AccountDetailPage> openNoteSummaryDetail(String account) {
        return start -> start.clickNotesSummary()
                .switchToNoteSummaryFrame()
                .checkNotesSummaryAccountName(account)
                .switchToMainFrame();
    }

}
