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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.search.OPS001_S001_ClientSearchPageUfoOperations;
import cz.moneta.test.dsl.ufo.operations.search.SearchBy;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.EXE705_S001_PaymentRecordsToApprovePage;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.EXE705_S002_VerificationDataPage;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.TRA740_S001_CreateNewTransferPaymentOrderPage;

import java.util.function.Function;

import static cz.moneta.test.dsl.ufo.operations.ufoOperations.EXE705_S001_PaymentRecordsToApprovePage.*;

public class PaymentOrderTasks {

    private final Harness harness;

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

    public Function<OPS001_S001_ClientSearchPageUfoOperations, OPS001_S001_ClientSearchPageUfoOperations> createSimpleTransferPaymentOrder(String accountNumberPayer, String accountNumberRecipient, String amount) {
        return start -> start
                .clickCreateNewTransferPaymentOrder()
                .clickBackOfficeZaklad()
                .selectOrderType("Obecná")
                .fillPayerAccountNumber(accountNumberPayer)
                .fillRecipientAccountNumber(accountNumberRecipient)
                .fillAmount(amount)
                .clickSend()
                .checkTransactionSuccessfullyEstablished("Transakce byla úspěšně založena pod ID:")
                .saveTaskIDPaymentOrder()
                .clickHomePage();
    }

    public Function<OPS001_S001_ClientSearchPageUfoOperations, TRA740_S001_CreateNewTransferPaymentOrderPage> createTransferOrderForClient(String accountNumber) {
        return start -> start
                .fillSearchInput(accountNumber)
                .searchBy(SearchBy.ACCOUNT_NUMBER)
                .onClientDetailsPage()
                .clickAccountList()
                .clickTransactions()
                .clickTransactionOrder()
                .clickPaymentsZaklad();
    }

    public Function<EXE705_S002_VerificationDataPage, EXE705_S002_VerificationDataPage> fillPaymentVerificationForm(String amount) {
        return start -> start
                .fillAccountNumberPayer(harness.get(PAYER_ACCOUNT_NUMBER_KEY))
                .fillAccountNumberRecipient(harness.get(RECIPIENT_ACCOUNT_NUMBER_KEY))
                .fillAccountNumberRecipientBankCode("0600")
                .fillAmount(amount)
                .fillDueDate(harness.get(DUE_DATE_KEY));
    }

    public Function<EXE705_S001_PaymentRecordsToApprovePage, EXE705_S001_PaymentRecordsToApprovePage> saveTransferOrderInformation() {
        return start -> start
                .savePayerAccount()
                .saveRecipientAccount()
                .saveDueDate();
    }
}