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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.salesforce.data.EventData;
import cz.moneta.test.dsl.salesforce.data.OpportunityData;
import cz.moneta.test.dsl.salesforce.data.SaleData;
import cz.moneta.test.dsl.salesforce.pages.MainPage;
import cz.moneta.test.dsl.salesforce.pages.opportunities.SalesListPage;

import java.util.function.Function;

public class NewOpportunityTasks {
    private final Harness harness;

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

    public Function<MainPage, SalesListPage> newOpportunity(OpportunityData opportunityData, EventData eventData, SaleData saleData) {
        return start -> start
                .searchItem(opportunityData.getAccount())
                .clickAccountDetailOrTrySearchAgain(opportunityData.getAccount(), 30)
                .clickOpportunities()
                .newOpportunity()
                .selectOpportunityInitiator(opportunityData.getInitiator())
                .selectOpportunityCategory(opportunityData.getCategory())
                .inputOpportunityBranch(opportunityData.getBranch())
                .selectOpportunityBranch()
                .fillOpportunityAmount(opportunityData.getAmount())
                .selectOpportunityCurrency(opportunityData.getCurrency())
                .fillOpportunityProbability(opportunityData.getProbability())
                .selectProductPotentials(opportunityData.getProductPotential())
                .clickCreate()
                .newEvent()
                .selectEventType(eventData.getType())
                .selectEventStatus(eventData.getStatus())
                .selectEventBusinessStatus(eventData.getBusinessStatus())
                .clickEventDate()
                .saveEvent()
                .clickSales()
                .newSale()
                .saleNext()
                .selectCharacterProduct(saleData.getProductType())
                .selectLoanType(saleData.getLoanType())
                .typeAmount(saleData.getAmount())
                .saveSale();
    }
}
