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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.tasks.accountenums.DebitCardFeePlan;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.*;
import cz.moneta.test.dsl.ufo.banka.pages.common.pages.OBR001_S001_PrintInstructionPage;
import cz.moneta.test.dsl.ufo.banka.pages.common.pages.OBR001_S001_PrintInstructionPageTransitions;
import cz.moneta.test.dsl.ufo.banka.pages.income.PIM001_S001_IncomeEditPage;
import cz.moneta.test.dsl.ufo.banka.pages.loans.*;
import cz.moneta.test.dsl.ufo.banka.pages.loans.flexikredit.NFL006_S001_FlexikreditScoringResultPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.*;
import cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.ODS003_S001_AddCodeOfRecommendedPersonPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.ODS003_S001_AddCodeOfRecommendedPersonPageTransitions;
import cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.PVX002_S002_AccountDispositionOwnerPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.PVX002_S002_AccountDispositionOwnerPageTransitions;
import cz.moneta.test.dsl.ufo.banka.pages.main.codelists.HCisProductClass;
import cz.moneta.test.dsl.ufo.banka.pages.main.codelists.Product;
import cz.moneta.test.dsl.ufo.banka.pages.products.debit.card.NPK001_S001_DebitCardRequestPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.saving.accounts.SPU001_S001_SavingAccountPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.saving.accounts.SPU001_S001_SavingAccountPageTransitions;
import cz.moneta.test.dsl.ufo.banka.pages.products.universal.request.UZO001_S001_UniverzalRequestIdentificationPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.universal.request.UZO006_S001_UniverzalRequestModeling;
import cz.moneta.test.dsl.ufo.banka.pages.requests.BAL006_S002_ClientRequestPageTransitions;
import cz.moneta.test.dsl.ufo.banka.pages.search.HLO001_S001_ClientSearchPage;
import cz.moneta.test.dsl.ufo.banka.tasks.accountenums.CurrentAccountsEnum;
import cz.moneta.test.dsl.ufo.banka.tasks.cards.CreditCardsTasks;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.code.lists.HCisAllStavZadosti;
import cz.moneta.test.dsl.util.code.lists.HCisDoklady;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.web.Lookup;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.function.Function;

import static cz.moneta.test.dsl.ufo.banka.pages.fon.CIF113_S001_ChangeDataFO.*;
import static cz.moneta.test.dsl.ufo.banka.pages.ib.ADC001_S001_IbPasswordKeyPage.PASSWORD_PLUS_MK;
import static cz.moneta.test.dsl.ufo.banka.pages.income.PIM001_S001_IncomeEditPage.INCOME_SUBTYPE_SELECT;
import static cz.moneta.test.dsl.ufo.banka.pages.main.BAL001_S008_SummaryStartDocumentsPage.ACCOUNT_NUMBER_KEY;
import static cz.moneta.test.dsl.ufo.banka.pages.main.codelists.HCisProductClass.*;
import static cz.moneta.test.dsl.ufo.banka.pages.main.signature.patterns.NPV010_S001_PrintSignPadPage.PAGE_LABEL_XPATH;
import static cz.moneta.test.dsl.ufo.banka.pages.products.current.account.BPP001_S001_DocumentationSendPage.BPP001_S001_PAGE_LABEL_XPATH;

public class NewProductTasks {

    private final Harness harness;

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

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> ibWithMobileKey(NonClient nonClient) {
        return start -> start.createNewProduct(ADC_IB_MK)
                .onIbPasswordKeyPage()
                .insertEnvelopeNumber()
                .selectLoginMethod(PASSWORD_PLUS_MK)
                .enterMobilePhoneNumber(nonClient.mobileNumber())
                .clickContinueToSettingADCPage()
                .clickSave()
                .onPrintOptionsPage()
                .clickPostponePrint()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(Product.ADC_IB_MK_ACTIVE.getValue());
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewCurrentAccount(CurrentAccountsEnum feePlan) {
        if (feePlan == CurrentAccountsEnum.TOM) {
            return start -> start.then(useFlow(feePlan))
                    .clickContinueToSuspendDispositionPrintPage()
                    .clickDoNotPrintEmpowermentNow()
                    .clickClientAgreedAndSignedAll()
                    .storeCurrentAccountNumber()
                    .clickContinue()
                    .onMainClientPage()
                    .checkProductActive(feePlan.getAccountName());
        } else {
            return start -> start.then(useFlow(feePlan))
                    .clickContinueToPrintOptionsPage()
                    .clickPostponePrint()
                    .onContractDocumentationPage()
                    .clickContinueSummaryStartDocumentsPage()
                    .storeCurrentAccountNumber()
                    .clickContinue()
                    .onMainClientPage()
                    .checkProductActive(feePlan.getAccountName());
        }
    }

    private Function<HKO101_S001_MainClientPage, OBR001_FlexiCreditRecommendationPage> useFlow(CurrentAccountsEnum feePlan) {
        return start -> start.createNewProduct(HCisProductClass.CURRENT_ACCOUNT)
                .onCurrentAccountPage()
                .selectFeePlan(feePlan.getAccountName())
                .clickConfirm()
                .onPreContractInformationPage()
                .clickOnSignedAndContinueDocumentsProvidedToClientPage()
                .clickContinue()
                .onAccountDispositionOwnerPage()
                .clickNotCreateNow()
                .clickSkipCreate()
                .onAddCodeOfRecommendedPersonPage()
                .checkProductNotRecommended()
                .clickWithoutRecommendationAndDismissAlertIfvisible()
                .onFlexiCreditRecommendationPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewCurrentAccount(String feePlan) {
        return start -> start.createNewProduct(HCisProductClass.CURRENT_ACCOUNT)
                .onCurrentAccountPage()
                .selectFeePlan(feePlan)
                .clickDispositionRadioNo()
                .clickConfirm()
                .onSignerPage()
                .clickSignedAndContinueToPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
                .onPrintInstructionPage()
                .clickCenterButton()
                .onDispositionGeneratePage()
                .clickGenerateNow()
                .onPrintPage()
                .closePrintWindow()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onSummaryStartDocumentsPage()
                .logAccountNumber()
                .clickContinue()
                .then(continueIfOnOpFoundPage())
                .checkProductActive(feePlan);
    }

    public Function<BAL001_S008_SummaryStartDocumentsPageTransitions, HKO101_S001_MainClientPage> continueIfOnOpFoundPage() {
        if (harness.getEndpoint(UfoEndpoint.class).isElementVisible("//*[text()='OP nalezen']", Lookup.XPATH)) {
            return start -> start
                    .onOpFoundPage()
                    .clickLeftButton()
                    .onMainClientPage();
        } else {
            return start -> start.onMainClientPage();
        }
    }

    public Function<PSP004_S001_PrintPageTransitions, NEP028_S001_SignaturePage> skipOpFoundPageIfVisible() {
        if (harness.getEndpoint(UfoEndpoint.class).isElementVisible("//*[text()='OP nalezen']", Lookup.XPATH)) {
            return start -> start
                    .onContractSignPage()
                    .clickLeftButton()
                    .onSignaturePage();
        } else return start -> start
                .onSignaturePage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createCurrentAccountNew(String feePlan) {
        return start -> start.createNewProduct(HCisProductClass.CURRENT_ACCOUNT)
                .onCurrentAccountPage()
                .selectFeePlan(feePlan)
                .clickConfirm()
                .onCitizenSignatureInformation()
                .clickContinue()
                .onPreContractualInformationPage()
                .clickOnSignedAndContinueDocumentsProvidedToClientPage()
                .clickContinue()
                .onPrintInstructionPage()
                .clickRightButton()
                .onAccountDispositionOwnerPage()
                .clickNotCreateNow()
                .clickSkipCreate()
                .onAddCodeOfRecommendedPersonPage()
                .checkProductNotRecommended()
                .clickWithoutRecommendationAndDismissAlertIfvisible()
                .onDispositionPage()
                .clickGenerateLater()
                .onSummaryStartDocumentsPage()
                .logAccountNumber()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(feePlan);
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewDebitCardForExistingCurrentAccount(String cardName, DebitCardFeePlan feePlan) {
        return start -> start.createNewProduct(DEBIT_CARD)
                .onSelectionOfSubmittedDocumentsPage()
                .selectIdCardRadio()
                .clickDocumentsCheckButton()
                .clickContinue()
                .onDebitCardRequestPage()
                .selectCurrentAccountByIndex(2)
                .selectDebitCardType(cardName + "|Nabízet")
                .selectDebitCardFeePlan(feePlan)
                .typeActivatePassword("000000")
                .clickClientDataHolderButton()
                .clickEnterButton()
                .onAddHolderPage()
                .clickOnHolderOwnerButton()
                .clickCardDeliveryToPermanentAddress()
                .clickPinDeliveryToPermanentAddress()
                .dismissPinChargeAlert()
                .waitForLoadAndClickSend()
                .onSignerSelectionPage()
                .chooseCitizen()
                .clickContinue()
                .onColdNotPrintFeeCatalogPage()
                .clickOK()
                .continueToGeneralContractAndDispositionPage()
                .continueToSummaryPage()
                .checkTextLabelContent("Debetní karta byla úspěšně založena")
                .clickOk()
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, NPK001_S001_DebitCardRequestPage> debitCardCommonPart(long accountNumber, String cardName, DebitCardFeePlan feePlan) {
        return start -> start.createNewProduct(DEBIT_CARD)
                .onSelectionOfSubmittedDocumentsPage()
                .selectIdCardRadio()
                .clickDocumentsCheckButton()
                .clickContinue()
                .onDebitCardRequestPage()
                .selectCurrentAccount(accountNumber)
                .selectDebitCardType(cardName + "|")
                .selectDebitCardFeePlan(feePlan)
                .typeActivatePassword("000000")
                .clickClientDataHolderButton()
                .clickEnterButton()
                .onAddHolderPage()
                .clickOnHolderOwnerButton()
                .clickDesignButtonIfSelectIsNotEnabled()
                .selectCardVariant("Standard")
                .clickCardDeliveryToPermanentAddress()
                .clickPinDeliveryToPermanentAddress()
                .dismissPinChargeAlert();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewDebitCardForExistingCurrentAccount(long accountNumber, String cardName, DebitCardFeePlan feePlan) {
        return start -> start
                .then(debitCardCommonPart(accountNumber, cardName, feePlan))
                .waitForLoadAndClickSend()
                .onFinalSignature()
                .continueToGeneralContractAndDispositionPage()
                .continueToSummaryPage()
                .checkTextLabelContent("Debetní karta byla úspěšně založena")
                .clickOk()
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> verifyDebitCardDetails(
            NonClient nonClient, String cardName, String feeType, String cardStatus, String atmLimit, String posLimit, String onlineLimit, String activationPassword) {
        return start -> start.openProductDetail(cardName)
                .onDebitCardDetailPage()
                .assertCardType(cardName)
                .assertCardFeeType(feeType)
                .assertCardStatus(cardStatus)
                .assertCardholderName(nonClient.firstName().toUpperCase() + " " + nonClient.lastName().toUpperCase())
                .assertATMLimit(atmLimit)
                .assertPOSLimit(posLimit)
                .assertInternetAMOTOLimit(onlineLimit)
                .assertActivationPassword(activationPassword)
                .clickBackToClient();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> verifyCreditCardDetails(String cardName) {
        return start -> start.openProductDetail(cardName)
                .onCreditCardDetailPage()
                .storeContractNumber()
                .assertPaymentMethod("Inkasem z účtu")
                .clickBackToClient();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> verifyCurrentAccountDetails(
            String accountName, String balance, String currency, String product, String openedDate, String paymentMethod) {
        return start -> start.openProductDetail(accountName)
                .onCurrentAccountDetailsPage()
                .assertAccountBalance(balance)
                .assertAccountCurrency(currency)
                .assertProduct(product)
                .assertAccountOpeningDate(openedDate)
                .assertPaymentMethod(paymentMethod)
                .clickBackToClient();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createIBAndCurrentAccount(CurrentAccountsEnum feePlan, String mobilePhoneNumber) {
        return start -> start.createNewProduct(CURRENT_ACCOUNT)
                .onCurrentAccountPage()
                .selectFeePlan(feePlan.getAccountName())
                .clickDispositionRadioYes()
                .clickConfirm()
                .onPrintPage()
                .closePrintWindow()
                .onPreContractualInformationPage()
                .clickOnSignedAndContinueDocumentsProvidedToClientPage()
                .clickContinue()
                .onAccountDispositionOwnerPage()
                .clickOwnerOnly()
                .onPrintPage()
                .closePrintWindow()
                .onConfirmationPage()
                .clickConfirmed()
                .onAddCodeOfRecommendedPersonPage()
                .checkProductNotRecommended()
                .clickWithoutRecommendationAndDismissAlertIfvisible()
                .onPrintInstructionPage()
                .clickCenterButton() //TODO: fixit
                .onMainClientPage()
                .createNewProduct(ADC_IB_MK)
                .onIbTypeSelectionPage()
                .clickActiveToIbPage()
                .enterMobilePhoneNumber(mobilePhoneNumber)
                .clickContinue()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
//                .onSettingAdcPage()//PPE
//                .clickSave()//ppe
                .onClientCardSentByEmailPage()
                .clickContineButton()
                .clickGenerateLater()
                .onPrintPage()
                .closePrintWindow()
                .onContractDocumentationPage()
                .clickContinue()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage();
    }

    public Function<UZO001_S001_UniverzalRequestIdentificationPage, UZO001_S001_UniverzalRequestIdentificationPage> addOtherApplicant(String birthNumber) {
        return start -> start
                .clickOtherApplicant()
                .clickFillInApplicant()
                .fillSearchTerm(birthNumber)
                .clickSearchByRc()
                .clickSearch()
                .onUniversalRequestIdentificationPage()
                .selectRelationshipWithMainApplicant("Manžel/manželka");
    }

    public Function<DOK001_S001_SelectionOfSubmittedDocumentsPage, NEP002_S001_ApplicantPage> selectPersonalIds() {
        return start -> start
                .selectIdCardRadio()
                .selectPassportRadio()
                .clickDocumentsCheckAndContinue()
                .onCreditCardApplicantPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createUzofkaWithOtherApplicant(NonClient clientData, int loanAmount, int term, String otherApplicantBirthNumber) {
        return start -> start.createNewProduct(UNIVERSAL_REQUEST)
                .onUniversalRequestPage()
                .typeIntoLoanAmount(loanAmount)
                .selectNumberOfInstallments(term)
                .selectPrimaryRequiredProduct("Expres půjčka")
                .checkMonthlyInstallmentNotEmpty()
                .clickNotIncludeExternCommitments()
                .fillRequiredIncrease("100")
                .then(addOtherApplicant(otherApplicantBirthNumber))
                .clickOtherApplicant()
                .clickContinue()
                .onSelectionOfSubmittedDocumentsPage()
                .then(selectPersonalIds())
                .checkCorrespondenceAddress(harness.get(ADDRESS_KEY))
                .checkDependantsNumber(harness.get(DEPENDANTS_NUMBER_KEY))
                .then(fillApplicantPage(clientData, true))
                .selectFirstIncome()
                .clickContinue()
                .onIdSelectionPage()
                .then(selectPersonalIds())
                .then(fillApplicantPage(clientData, true))
                .isSameHouseHold("Ano")
                .selectFirstIncome()
                .clickContinue()
                .onSignerSelectionPage()
                .clickSignedPersonallyPhysicallyAndContinue()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onUniversalApplicationSignaturePage()
                .clickApplicantCheckbox()
                .clickSecondApplicantCheckbox()
                .clickYesButton()
                .waitForLoader()
                .onUniversalApplicationScoringResultPage()
                .waitForStatusAndRefresh("varianty navrženy")
                .checkApprovedOffersVisible()
                .then(calculateProductsCombinations())
                .clickEndButton()
                .onMainClientPage();
    }


    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createUzofka(NonClient clientData, int loanAmount, int term) {
        return start -> start.createNewProduct(UNIVERSAL_REQUEST)
                .onUniversalRequestPage()
                .typeIntoLoanAmount(loanAmount)
                .selectNumberOfInstallments(term)
                .selectPrimaryRequiredProduct("Expres půjčka")
                .checkMonthlyInstallmentNotEmpty()
                .clickNotIncludeExternCommitments()
                .fillRequiredIncrease("100")
                .clickContinue()
                .onSelectionOfSubmittedDocumentsPage()
                .then(selectPersonalIds())
                .then(fillApplicantPage(clientData, true))
                .selectFirstIncome()
                .clickContinue()
                .onSignerSelectionPage()
                .clickSignedPersonallyPhysicallyAndContinue()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onUniversalApplicationSignaturePage()
                .clickApplicantCheckbox()
                .clickYesButton()
                .waitForLoader()
                .onUniversalApplicationScoringResultPage()
                .storeAppKey()
                .clickEndButton()
                .onMainClientPage()
                .selectFromListOfRequests()
                .selectProductFilter("Expres půjčka")
                .selectFirstApplication()
                .clickOpenRequestDetail()
                .onUniverzalRequestModelingPage()
                .waitForStatusAndRefresh("varianty navrženy")
                .checkApprovedOffersVisible()
                .clickEndButton()
                .onListOfRequests()
                .clickBackToMainPage();
    }

    public Function<UZO006_S001_UniverzalRequestModeling, UZO006_S001_UniverzalRequestModeling> calculateProductsCombinations() {
        return start -> start
                .clickCalculator()
                .selectCredit("Core Expres|50000|24|")
                .fillCreditAmount("50000")
                .selectInsurance("Bez pojištění")
                .clickCalculation()
                .checkPaymentNotEmpty()
                .checkCreditRateNotEmpty()
                .checkRpsnNotEmpty()
                .checkInsuranceChargeNotEmpty()
                .selectRecalculation("Flexikredit|50000|")
                .clickRecalculate()
                .checkDoNotAcceptThirdProductIsVisible()
                .clickBack();
    }

    public Function<NEP028_S001_SignaturePage, CAS001_S001_ScoringPageTransitions> finishLoanApplication() {
        return start -> start
                .clickApplicantSignatureCheckbox()
                .clickYes()
                .onScoringPage()
                .waitForLoader();
    }

    public Function<NEP001_S004_ApplicationDataPage, NEP028_S001_SignaturePage> fillApplicationDataPage(String insurance) {
        return start -> start
                .selectInsurance(insurance)
                .clickSaveButton()
                .onSignerSelectionPage()
                .clickSignedPersonallyAndContinue()
                .closePrintWindow()
                .onSignaturePage();
    }

    public Function<ODS003_S001_AddCodeOfRecommendedPersonPage, ODS003_S001_AddCodeOfRecommendedPersonPageTransitions> fillPromoCodePage() {
        return start -> start.checkProductNotRecommended()
                .clickWithoutRecommendation();
    }

    public Function<DOK001_S001_SelectionOfSubmittedDocumentsPage, NEP002_S001_ApplicantPage> selectIDs() {
        return start -> start.selectIdCardRadio()
                .selectDriverLicenceRadio()
                .clickDocumentsCheckButton()
                .clickContinue()
                .onCreditCardApplicantPage();
    }

    public Function<NEP002_S001_ApplicantPage, NEP002_S001_ApplicantPage> fillApplicantPage(NonClient nonClient, boolean createNewIncome) {
        return start -> {
            UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
            NEP002_S001_ApplicantPage page = start
                    .then(fillIncomePage(nonClient, createNewIncome))
                    .fillPaymentsOutsideMMB(nonClient.otherLoanPayments())
                    .fillOtherMonthlyExpenses(nonClient.otherExpenses() + nonClient.housingExpenses())
                    .fillHouseholdIncome(nonClient.homeIncome());
            if (endpoint.isElementVisible(3, NEP002_S001_ApplicantPage.SAME_HOUSEHOLD_SELECT, Lookup.ID)) {
                page = page.isSameHouseHold("Ne");
            }
            return page;
        };
    }

    private Function<NEP002_S001_ApplicantPage, NEP002_S001_ApplicantPage> fillIncomePage(NonClient nonClient, boolean createNewIncome) {
        if (createNewIncome) {
            return start -> start
                    .clickEditIncomeButton()
                    .clickAddIncomeButton()
                    .selectIncomeType(nonClient.incomeType().getUfoValue())
                    .selectIncomeSubtype(nonClient.incomeSubtype().getUfoValue())
                    .selectOccupation(nonClient.occupationType().getUfoValue())
                    .then(finishSettingIncome(nonClient));
        } else {
            return start -> start
                    .clickEditIncomeButton()
                    .then(finishSettingIncome(nonClient));
        }
    }

    private Function<NEP002_S001_ApplicantPage, NEP002_S001_ApplicantPage> fillIncomePageRetirement(NonClient nonClient, boolean createNewIncome) {
        if (createNewIncome) {
            return start -> start
                    .clickEditIncomeButton()
                    .clickAddIncomeButton()
                    .selectIncomeType(nonClient.incomeType().getUfoValue())
                    .selectIncomeSubtype(nonClient.incomeSubtype().getUfoValue())
                    .selectOccupation(nonClient.occupationType().getUfoValue())
                    .then(finishSettingIncome(nonClient));
        } else {
            return start -> start
                    .clickEditIncomeButton()
                    .then(finishSettingIncome(nonClient));
        }
    }

    private Function<PIM001_S001_IncomeEditPage, NEP002_S001_ApplicantPage> finishSettingIncome(NonClient nonClient) {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(5, INCOME_SUBTYPE_SELECT);
        if (endpoint.getSelectedFirstItemText(INCOME_SUBTYPE_SELECT, Lookup.ID).equals("Invalidní důchod")) {
            return start -> start
                    .then(finishSettingIncomeRetirement(nonClient));
        } else {
            return start -> start
                    .then(finishSettingIncomeOther(nonClient));
        }

    }

    private Function<PIM001_S001_IncomeEditPage, NEP002_S001_ApplicantPage> finishSettingIncomeOther(NonClient nonClient) {
        return start -> start
                .openSearchEmployerWindow()
                .fillCompanyNameOrIco(nonClient.employer().getName())
                .clickSearchCompanyButton()
                .selectCompanyNameRow(nonClient.employer().getName())
                .clickSelectEmployerButton()
                .selectIncomeSubtype(nonClient.incomeSubtype().getUfoValue())
                .selectOccupation(nonClient.occupationType().getUfoValue())
                .clickIncomeCashNoRadio()
                .clickNoticePeriodNoRadio()
                .clickTrialPeriod(nonClient)
                .fillEmploymentStartDate(DateUtils.getDateWithFormat(nonClient.occupationEmploymentFromRaw(), "d.M.yyyy"))
                .then(fillEmploymentEndDateIfVisible(DateUtils.getDateWithFormat(nonClient.occupationEmploymentTillRaw(), "d.M.yyyy")))
                .fillPhoneCountryCode("420")
                .fillPhoneNumber(nonClient.employer().getPhoneNumber())
                .fillNetIncome(nonClient.netMonthlyIncome())
                .clickAcceptIncomeButton()
                .clickBackButton()
                .onApplicantPage();

    }

    private Function<PIM001_S001_IncomeEditPage, PIM001_S001_IncomeEditPage>
    fillEmploymentEndDateIfVisible(String date) {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(3, PIM001_S001_IncomeEditPage.EMPLOYMENT_END_DATE_INPUT, Lookup.ID)) {
            return start -> start.fillEmploymentEndDate(date);
        } else {
            return start -> start;
        }
    }

    private Function<PIM001_S001_IncomeEditPage, NEP002_S001_ApplicantPage> finishSettingIncomeTrialTrue(NonClient nonClient) {
        return start -> start
                .openSearchEmployerWindow()
                .fillCompanyNameOrIco(nonClient.employer().getName())
                .clickSearchCompanyButton()
                .selectCompanyNameRow(nonClient.employer().getName())
                .clickSelectEmployerButton()
                .clickIncomeCashNoRadio()
                .clickNoticePeriodNoRadio()
                .clickTrialPeriodNoRadio()
                .fillEmploymentStartDate(DateUtils.getDateWithFormat(nonClient.occupationEmploymentFromRaw(), "d.M.yyyy"))
                .fillPhoneCountryCode("420")
                .fillPhoneNumber(nonClient.employer().getPhoneNumber())
                .fillNetIncome(nonClient.netMonthlyIncome())
                .clickAcceptIncomeButton()
                .clickBackButton()
                .onApplicantPage();
    }

    private Function<PIM001_S001_IncomeEditPage, NEP002_S001_ApplicantPage> finishSettingIncomeRetirement(NonClient nonClient) {
        return start -> {
            UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
            boolean canAccept = endpoint.isElementVisible(3, PIM001_S001_IncomeEditPage.ACCEPT_INCOME, Lookup.ID);
            boolean canSave = endpoint.isElementVisible(3, PIM001_S001_IncomeEditPage.SAVE_INCOME_BUTTON, Lookup.ID);
            if (!canAccept || !canSave) {
                return start
                        .clickBackButton()
                        .onApplicantPage();
            }
            return start
                    .clickAcceptIncome()
                    .clickAcceptIncomeButton()
                    .clickBackButton()
                    .onApplicantPage();
        };
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewSavingsAccount(String product) {
        return start -> start
                .createNewProduct(HCisProductClass.SAVINGS_ACCOUNT)
                .onRegistrationCertificatePage()
                .clickRightButton()
                .then(sendDocumentIfVisible())
                .selectProduct("SÚ_PRO_podnikání_6_FOP")
                .selectFirstAccountNumber()
                .selectDistribution("Elektronicky IB")
                .selectPeriodicity("Měsíční")
                .clickSend()
                .then(sendDocumentationIfVisible())
                .clickNotCreateNow()
                .clickSkipCreate()
                .onPrintInstructionPage()
                .clickCenterButton()
                .onPrintInstructionPage()
                .clickRightButton()
                .onSignerSelectionsPage()
                .clickSignedPersonallyAndContinueToPrint()
                .saveDocumentUrl()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(product);
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createSavingAccountWithInternetBanking() {
        return start -> start
                .createNewProduct(HCisProductClass.SAVINGS_ACCOUNT)
                .onRegistrationCertificatePage()
                .clickRightButton()
                .onSavingsAccountPage()
                .selectProduct("SÚ_PRO_podnikání_6_PO")
                .selectFirstAccountNumber()
                .selectDistribution("Elektronicky IB")
                .selectPeriodicity("Měsíční")
                .clickSend()
                .onCreateElectronicDistributionChannel()
                .selectDistributionChannel("IB Heslo/MK")
                .clickContinueDismissAlertIfPresent()
                .onDocumentationSendPage()
                .sendDocumentsToClient()
                .clickLeftButton()
                .onAppendixSignedPage()
                .clickNoButton()
                .clickCenterButton()
                .onPrintInstructionPage()
                .clickLeftButton()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage()
                .verifySavingAccountEstablishedSuccessfully();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewMutualFunds() {
        String accountNumber = harness.get(BAL001_S008_SummaryStartDocumentsPage.ACCOUNT_NUMBER_KEY);

        return start -> start.createNewProduct(HCisProductClass.MUTUAL_FUNDS)
                .onMutualFundsCIFdataPage()
                .selectCzechRepublicTaxDomicil("Česká republika")
                .clickNextButtonToInvestmentForm()
                .selectEducationCombo("Vysokoškolské ekonomické")
                .clickDepositAccountRadioBtn()
                .clickPensionOrLifeInsuranceRadioBtn()
                .clickMonetaryOrBondFundsRadioBtn()
                .clickEquityFundsRadioBtn()
                .clickIndividualInvestmentProductsRadioBtn()
                .clickLowestRiskSavingsRadioBtn()
                .clickHighestRiskEquitiesRadioBtn()
                .clickSavingsRadioBtn()
                .clickLessThanTwoYearsAgoRadioBtn()
                .clickMaxTwicePerYearRadioBtn()
                .clickRaiseValueRadioBtn()
                .clickNoInfluenceRadioBtn()
                .selectInvestmentHorizonCombo("3 roky a více")
                .clickSendButton()
                .clickContinue()
                .onInvestmentFormSigningPage()
                .clickSignedButton()
                .clickContinueButton()
                .selectClientStatementDistribution("Poštou")
                .selectBuRadioBtn()
                .selectAccountNumberForSettlement(accountNumber)
                .clickSendAndPrintButton()
                .dismissAlert()
                .clickContinue()
                .onContractInvestmentFormSigningPage()
                .clickSignedButton()
                .clickContinue()
                .onAccountDispositionOwnerPage()
                .clickNotCreateNow()
                .clickSkipCreate()
                .onMeetingRecordSigningPage()
                .clickContinueButton()
                .clickContinueButton()
                .clickSignedButton()
                .clickContinue()
                .onSummaryStartDocumentsPage()
                .storeMutualFundsNumber()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive("Podílové fondy");
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewCreditCardByQuickRequest(NonClient nonClient, CreditCardsAdvantages advantage, CreditCardsPromo promo, String creditAmount) {
        CreditCardsTasks creditCardTasks = harness.tasks().ufo().banka().cardsServicing().creditCards();

        return start -> start.createNewProduct(ONE_CLICK)
                .onQuickCreditCardRequestPage()
                .then(creditCardTasks.fillQuickCreditCardRequest(advantage, promo, creditAmount))
                .selectIdCardRadio()
                .selectPassportRadio()
                .clickDocumentsCheckAndContinue()
                .onCreditCardApplicantPage()
                .then(creditCardTasks.fillCreditCardApplicantInformation(nonClient))
                .clickApplicantSignatureCheckbox()
                .clickYes()
                .onScanDocumentsPage()
                .clickSkipButton()
                .onCreditCardScoringResultPage()
                .waitForStatusAndRefresh("SOUHLAS")
                .clickCreateProductAndPrintContract()
                .onPreContractualInformationPrintedPage()
                .continueToPrintCopyOfContractProposalPage()
                .clickContinue()
                .onSignerSelectionPage()
                .chooseCitizen()
                .clickContinue()
                .onSignContractPage()
                .clickFirstSignerCheckbox()
                .clickYesButton()
                .clickOk()
                .clickContinue()
                .clickContinue()
                .fillPriceLimitInput(creditAmount)
                .clickSaveButton()
                .clickSigned()
                .clickContinue()
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, NKK001_S007_QuickCreditCardApplicantInfoPage> createNewCreditCard(
            NonClient nonClient, ProductType productType, NeedInsurance needInsurance, CardBrand cardBrand,
            CreditCardsAdvantages advantage, CreditCardsPromo promo, String creditAmount,
            String cashDailyLimit, String purchaseDailyLimit, String onlineDailyLimit) {
        CreditCardsTasks creditCardTasks = harness.tasks().ufo().banka().cardsServicing().creditCards();

        return start -> start.createNewProduct(CREDIT_CARD)
                .onQuickCreditCardRequestPage()
                .then(creditCardTasks.fillCreditCardRequestForUpdate(advantage, promo, creditAmount, needInsurance, productType, cardBrand))
                .setDailyLimitForWithdraw(cashDailyLimit)
                .setDailyLimitForPurchases(purchaseDailyLimit)
                .setDailyLimitForOnlinePurchases(onlineDailyLimit)
                .setActivationPassword("111111")
                .selectRepaymentMethod(RepaymentMethod.INKASO)
                .selectStatementDistributionMethod(StatementDistributionMethod.ELECTRONICALLY_IB)
                .selectPinDistributionMethod(PinDistributionMethod.POST)
                .dismissPinChargeAlert()
                .selectDebitAccountType(DebitAccountType.DEBIT_ACCOUNT_MMB)
                .selectCreateAccountForCard(NeedAccount.YES)
                .selectGetInsurance(NeedInsurance.NO);
    }

    public Function<HKO101_S001_MainClientPage, BAL006_S002_ClientRequestPageTransitions> showApplicationDetails(String applicationID) {
        return start -> start.selectFromListOfRequests()
                .clickRequest(applicationID)
                .clickOpenRequestDetail();
    }

    //application is already selected, when client has only one
    public Function<HKO101_S001_MainClientPage, BAL006_S002_ClientRequestPageTransitions> showApplicationDetailsSingleApplication() {//application is already selected, when client has only one
        return start -> start.selectFromListOfRequests()
                .clickOpenRequestDetail();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewBuildingSavings(String contract) {
        return start -> start.createNewProduct(HCisProductClass.BUILDING_SAVINGS)
                .onBuildingSavingsPage()
                .clickStateOfBirthButton()
                .fillIssuer("Praha")
                .continueToParametersPage()
                .selectSymbol("Nespecifikováno")
                .selectActionCode("Bez zvýhodnění")
                .fillAmount("500000")
                .clickStateSupportYes()
                .clickAnnualReportByPost()
                .clickPhysicalConsentYes()
                .continueToConfirmationPage()
                .clickContinue()
                .onBuildingSavingsConsentPage()
                .continueToProductsListPage()
                .clickContinueButtonAndContinueToMainClientPage()
                .checkProductActive(contract);
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewGroupInsurance(String insurance) {
        return start -> start.createNewProduct(HCisProductClass.INSURANCE)
                .onInsuranceTypeSelectionPage()
                .clickGroupButton()
                .selectInsurance(insurance)
                .clickInsuranceForIndividuals()
                .selectAccount(harness.get(ACCOUNT_NUMBER_KEY))
                .clickContinue()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onSignerPage()
                .clickLeftButton()
                .onDispositionGeneratePage()
                .clickGenerateNow()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage()
                .checkInsuranceProduct(insurance);
    }

    //client must have IB
    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createSBA() {
        return start -> start.createNewProduct(ADC_SBA)
                .onDispositionGeneratePage()
                .clickGenerateLater()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage();
    }

    public Function<HLO001_S001_ClientSearchPage, HLO001_S001_ClientSearchPage> verifyApplicationSignature(String applicationId) {
        return start -> start
                .clickSecondSignature()
                .fillApplicationId(applicationId)
                .clickSecondSignatureButton()
                .clickVerifyAlternative()
                .clickOkAndCloseWindow();
    }

    public Function<HLO001_S001_ClientSearchPage, HLO001_S001_ClientSearchPage> verifyApplicationSignatureThirdWindow(String applicationId) {
        return start -> start
                .clickSecondSignature()
                .fillApplicationId(applicationId)
                .clickSecondSignatureButton()
                .clickVerifyAlternative()
                .clickOkAndCloseWindow();
    }

    public HKO101_S001_MainClientPage createClientWithIb(Harness harness, Credentials credentials, NonClient applicant) {
        return harness.tasks().ufo().banka().newClient()
                .openUfoAndCreateClient(harness, credentials, applicant)
                .then(createIBAndCurrentAccount(CurrentAccountsEnum.TOM_PLUS, applicant.mobileNumber()));
    }

    public HLO001_S001_ClientSearchPage openUfoAndVerifyApplicationAsSecondBanker(Credentials credentials, String applicationId) {
        return harness.withUfoSecondInstance()
                .openLoginPage()
                .then(harness.tasks().ufo().banka().login().withCredentialsAndSelectFirstOmAndTurnOffSignpad(credentials))
                .then(verifyApplicationSignature(applicationId));
    }

    public Function<HKO101_S001_MainClientPage, NFL006_S001_FlexikreditScoringResultPage> createNewFlexikreditPart1(NonClient nonClient) {
        return start -> (NFL006_S001_FlexikreditScoringResultPage) start.createNewProduct(FLEXIKREDIT)
                .onFlexikreditPage()
                .checkAlertMessageAfterFillingAmountOutsideOfRange(1000)
                .checkAlertMessageAfterFillingAmountOutsideOfRange(105000)
                .fillAmount(3000)
                .clickNoPromoIfVisible()
                .clickChangeParameters()
                .clickSend()
                .onFlexikreditScoringApplicationIdentificationPage()
                .clickContinue()
                .selectIdCardRadio()
                .selectPassportRadio()
                .clickDocumentsCheckAndContinue()
                .onCreditCardApplicantPage()
                .then(checkClientDetailInfo())
                .clickEditIncomeButton()
                .clickAddIncomeButton()
                .selectIncomeType("Příjem ze závislé činnosti")
                .selectIncomeSubtype("Příjem ze závislé činnosti na dobu neurčitou")
                .selectOccupation("it programátor/software developer")
                .openSearchEmployerWindow()
                .fillCompanyNameOrIco(harness.getConfig("branch.ico"))
                .clickSearchCompanyButton()
                .clickFirstCompany()
                .clickSelectEmployerButton()
                .clickTrialPeriodNoRadio()
                .clickNoticePeriodNoRadio()
                .clickIncomeCashNoRadio()
                .fillEmploymentStartDate(LocalDate.now().minusYears(2).format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))
                .fillPhoneNumber("420" + nonClient.mobileNumber())
                .fillNetIncome(50000)
                .clickAcceptIncomeButtonAndDisableAlertIfVisible()
                .clickBackButton()
                .onApplicantPage()
                .fillPaymentsOutsideMMB(0)
                .fillOtherMonthlyExpenses(1000)
                .fillHouseholdIncome(80000)
                .selectFirstIncome()
                .clickContinue()
                .onSignerSelectionPage()
                .clickSignedPersonallyPhysicallyAndContinue()
                .onPrintPage().saveDocumentUrl()
                .closePrintWindow()
                .onSignaturePage()
                .clickApplicantSignatureCheckbox()
                .clickYes()
                .onScoringPage()
                .waitForLoader()
                .onFlexikreditScoringResultPage()
                .storeAppKey()
                .storeAppId()
                .storeAppStat();
    }

    public Function<NEP002_S001_ApplicantPage, NEP002_S001_ApplicantPage> checkClientDetailInfo() {
        return start -> start
                .checkBirthNumber(harness.get(BIRTH_NUMBER_KEY))
                .checkLastName(harness.get(LAST_NAME_KEY))
                .checkFirstName(harness.get(FIRST_NAME_KEY))
                .checkMaritalStatus(harness.get(MARITAL_STATUS_KEY))
                .checkHousingType(harness.get(HOUSING_TYPE_KEY))
                .checkEducation(harness.get(EDUCATION_KEY))
                .checkNationality(harness.get(NATIONALITY_KEY))
                .checkFirstIdCardType(harness.get(FIRST_ID_CARD_TYPE_KEY))
                .checkFirstIdCardNumber(harness.get(FIRST_ID_CARD_NUMBER_KEY))
                .checkFirstIdCardExpirationDate(harness.get(FIRST_ID_CARD_EXPIRATION_DATE_KEY))
                .checkSecondIdCardType(harness.get(SECOND_ID_CARD_TYPE_KEY))
                .checkSecondIdCardNumber(harness.get(SECOND_ID_CARD_NUMBER_KEY))
                .checkSecondIdCardExpirationDate(harness.get(SECOND_ID_CARD_EXPIRATION_DATE_KEY))
                .checkAddress(harness.get(ADDRESS_KEY))
                .checkLandline(harness.get(LANDLINE_KEY))
                .checkMobilePhone(harness.get(MOBILE_PHONE_KEY))
                .checkEmail(harness.get(EMAIL_KEY))
                .checkDependantsNumber(harness.get(DEPENDANTS_NUMBER_KEY));
    }

    public Function<NFL006_S001_FlexikreditScoringResultPage, VER017_S001_SecondBankerVerificationStatusPage> createNewFlexikreditPart2(HCisAllStavZadosti expectedAppStat, String bankerName) {
        return start -> start
                .waitForStatusAndRefresh(expectedAppStat.getValue())
                .clickFoundationPrintContractButton()
                .onSelectingApprovedVariantsPage()
                .clickToLoanAmountRadioButton()
                .fillIntoLoanAmountIfVisible("4000")
                .clickSelectToPrint()
                .saveDocumentUrl()
                .closePrintWindow()
                .onInformationPrintedPage()
                .continueToPrintCopyOfContractProposalPage()
                .clickPrint()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onPrintCopyOfContractProposalSuccessfullPage()
                .clickContinue()
                .fillSurnameInput(bankerName)
                .clickSearch()
                .clickContinue()
                .onSecondBankerVerificationPage()
                .storeApplicationId();
        //pokračovat podpisem druhého bankéře
    }

    public Function<VER017_S001_SecondBankerVerificationStatusPage, HKO101_S001_MainClientPage> createNewFlexikreditPart3(String newProduct) {
        return start -> start
                .waitForStatus("Verifikace vyřízena")
                .clickContinue()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onPrintInstructionPage()
                .clickRightButton()
                .onSignContractor()
                .clickFirstSignerCheckbox()
                .clickYesButtonToClientContractSignPage()
                .clickLeftButton()
                .onFlexikreditScoringPage()
                .storeApprovedTableAmount()
                .storeApprovedTableInterest()
                .checkApplicationState("Rámec otevřen")
                .clickEnd()
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewCurrentAccountWithSelectProduct(CurrentAccountsEnum product) {
        return start -> start.createNewProduct(HCisProductClass.CURRENT_ACCOUNT)
                .onCurrentAccountPage()
                .selectProduct(product.getAccountName())
                .clickDispositionRadioYes()
                .clickConfirm()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
                .onAccountDispositionOwnerPage()
                .clickOwnerOnly()
                .onPrintInstructionPage()
                .clickCenterButton()
                .onPrintInstructionPage()
                .clickCenterButton()
                .onDispositionGeneratePage()
                .clickGenerateNow()
                .onPrintPage()
                .closePrintWindow()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onSummaryStartDocumentsPage()
                .logAccountNumber()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(product.getAccountName());
    }

    public Function<OBR001_S001_PrintInstructionPageTransitions, OBR001_S001_PrintInstructionPage> skipSignPadIfVisibleAfterPrintInstruction() {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, PAGE_LABEL_XPATH, Lookup.XPATH)) {
            return start -> start
                    .onPrintSignPadPage()
                    .clickContinue();
        } else {
            return start -> start
                    .onPrintInstructionPage();
        }
    }

    public Function<PVX002_S002_AccountDispositionOwnerPageTransitions, OBR001_S001_PrintInstructionPage> skipSignPadIfVisibleAfterAccountDisposition() {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, PAGE_LABEL_XPATH, Lookup.XPATH)) {
            return start -> start
                    .onPrintSignPadPage()
                    .clickContinue();
        } else {
            return start -> start
                    .onPrintInstructionPage();
        }
    }

    public Function<DOK001_S001_SelectionOfSubmittedDocumentsPage, NEP002_S001_ApplicantPage> selectSecondIdDocuments(HCisDoklady idType) {
        if (idType.equals(HCisDoklady.RP)) {
            return selectIDs();
        } else if (idType.equals(HCisDoklady.CP)) {
            return selectPersonalIds();
        } else {
            return null;
        }
    }

    public Function<OBR001_S001_PrintInstructionPageTransitions, SPU001_S001_SavingAccountPage> sendDocumentIfVisible() {
        UfoEndpoint endpoint = this.harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, BPP001_S001_PAGE_LABEL_XPATH, Lookup.XPATH)) {
            return start -> start
                    .onDocumentationSendPage()
                    .sendDocumentsToClient()
                    .clickLeftButton()
                    .onSavingsAccountPage();
        } else {
            return start -> start.onSavingsAccountPage();
        }
    }

    public Function<SPU001_S001_SavingAccountPageTransitions, PVX002_S002_AccountDispositionOwnerPage> sendDocumentationIfVisible() {
        UfoEndpoint endpoint = this.harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, BPP001_S001_PAGE_LABEL_XPATH, Lookup.XPATH)) {
            return start -> start
                    .onDocumentationSendPage()
                    .sendDocumentsToClient()
                    .clickLeftButton()
                    .onAccountDispositionOwnerPage();
        } else {
            return start -> start.onAccountDispositionOwnerPage();
        }
    }
}
