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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.cashman.enums.CashmanOrderStatus;
import cz.moneta.test.dsl.cashman.pages.CashmanHomePage;
import cz.moneta.test.dsl.cashman.pages.menu_OM.CashmanOMNewOrderPage;
import cz.moneta.test.dsl.util.data.payment.PaymentData;

import java.util.function.Function;

public class CashmanTasks {

    private final Harness harness;

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

    public LoginTasks loginTasks() {
        return new LoginTasks(harness);
    }

    public Function<CashmanHomePage, CashmanOMNewOrderPage> createNewOrder(PaymentData data) {
        return start -> start.clickOnOMAndChooseNewOrder()
                .selectOM3693()
                .createNewOrder()
                .fillRequiredDate(data.getTodayDate())
                .clickOnBillsFlagCheckBox()
                .fillLoansRegistrationNumbers(data.getLoansRegistrationNumbersAmount())
                .fillNominal100Amount(data.getBanknotesAmount())
                .fillNominal10Amount(data.getCoinsAmount())
                .fillNote(data.getName1());
    }

    public Function<CashmanOMNewOrderPage, CashmanOMNewOrderPage> checkOrderSummaries(PaymentData data) {
        return start -> start.checkBanknotesSummary(data.getBanknotesSummary())
                .checkCoinsSummary(data.getCoinsSummary())
                .checkSummary(data.getSummary());
    }

    public Function<CashmanOMNewOrderPage, CashmanHomePage> submitNewOrder(PaymentData data) {
        return start -> start.fillNominal10Amount(data.getCoinsAmount())
                .submitNewOrder()
                .sendNewOrder()
                .storeOrderId()
                .clickOnHomePage();
    }

    public Function<CashmanHomePage, CashmanHomePage> checkOrderPresence(PaymentData data, CashmanOrderStatus status) {
        return start -> start.clickOnOMAndChooseCzkPrague()
                .clickOnFilter()
                .fillOrderId(data.getOrderId())
                .clickOnWaitingFlag()
                .fillDateFrom(data.getTodayDate())
                .submitFilter()
                .waitForOrderIdPresence(data.getOrderId())
                .checkOrderStatus(status.getStatus())
                .clickOnHomePage();
    }

    public Function<CashmanHomePage, CashmanHomePage> checkOrderPresenceInDeposit(PaymentData data) {
        return start -> start.clickOnDepositAndChooseCzkPrague()
                .clickOnLevyOM()
                .waitForOrderIdPresence(data.getOrderId())
                .clickOnHomePage();
    }
}
