package cz.moneta.test.dsl.ufo.banka.tasks.products;

import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.codelists.HCisProductClass;
import cz.moneta.test.dsl.ufo.banka.pages.products.debit.card.SIF004_S001_ContactSettingsForSendingEmailsPage;
import cz.moneta.test.dsl.ufo.banka.pages.term.deposit.RTV001_S001_TermDepositPage;
import cz.moneta.test.dsl.ufo.banka.pages.term.deposit.RTV001_S004_FoundingDepositInformationPage;

import java.util.function.Function;

public class TermDepositTasks {

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createTermDeposit(String termDepositProducts, String depositAmount, String termDepositPeriod) {
        return start -> start
                .createNewProduct(HCisProductClass.ONETIME_TERM_DEPOSIT)
                .onRegistrationCertificatePage()
                .clickRightButton()
                .onTermDepositPage()
                .then(fillTermDepositInformation(termDepositProducts, depositAmount, termDepositPeriod))
                .then(fillContacts())
                .clickSaveToDocumentationSendPage()
                .sendDocumentsToClient()
                .clickLeftButton()
                .onAddCodeOfRecommendedPersonPage()
                .checkProductNotRecommended()
                .clickWithoutRecommendationAndDismissAlertIfvisible()
                .onDepositOfPrincipalTypePage()
                .clickParentAccountAndDismissAlertIfPresent()
                .saveDocumentUrl()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onPrintInstructionPage()
                .clickCenterButton()
                .onProductSummaryChangeAdcPage()
                .clickNoToDispositionGeneratePage()
                .clickGenerateNow()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage();
    }

    public Function<RTV001_S001_TermDepositPage, SIF004_S001_ContactSettingsForSendingEmailsPage> fillTermDepositInformation(String termDepositProducts, String depositAmount, String termDepositPeriod) {
        return start -> start
                .selectProduct(termDepositProducts)
                .fillInitialAmount(depositAmount)
                .selectPeriod(termDepositPeriod)
                .selectFirstAccountWhenFounded()
                .selectStatementDistribution("Elektronicky a e-mailem")
                .selectStatementPeriodicity("Po pohybu")
                .selectFirstDepositAccount()
                .selectFirstInterestAccount()
                .selectCorrespondenceAddress("Adresa trvalá")
                .clickSendToContactSettingsForSendingEmailsPage();
    }

    public Function<SIF004_S001_ContactSettingsForSendingEmailsPage, RTV001_S004_FoundingDepositInformationPage> fillContacts() {
        return start -> start
                .clickFillEmailFromCif()
                .clickFillPhoneFromCif()
                .clickContinue()
                .onFoundingDepositInformationPage();
    }
}
