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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.cards.debit.OBR003_S001_ClientContractSignPage;
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.sme.SMA002_S001_SMEAutomatsApplicationOverview;
import cz.moneta.test.dsl.ufo.banka.pages.requests.BAL006_S002_ClientRequestPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.debit.card.SIF004_S001_ContactSettingsForSendingEmailsPageTransitions;
import cz.moneta.test.dsl.ufo.banka.pages.products.sme.KUL001_S001_SelectProductsPage;
import cz.moneta.test.dsl.util.data.client.NonClient;

import java.util.function.Function;

import static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.OPN008_S001_SignContractPage.APPLICATION_ID_KEY;

public class NewSmeAutomatFopTasks {

    private final NewSmeAutomatSubTasks smeAutomatSubTasks;

    public NewSmeAutomatFopTasks(Harness harness) {
        this.smeAutomatSubTasks = harness.tasks().ufo().banka().newSmeAutomatSubTasks();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpresBusiness(Harness harness, String dummyEmail, String loanExpresAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("nákup strojů, výrobních zařízení", loanExpresAmount))
                .clickContinue()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostNettoIncome())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpresBusinessSendToNIB(Harness harness, String dummyEmail, String loanExpresAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("nákup strojů, výrobních zařízení", loanExpresAmount))
                .clickContinue()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.fillFinancialSignpostNettoIncome())
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .clickReturnToHKO();
    }

    public Function<HKO101_S001_MainClientPage, BAL006_S002_ClientRequestPage> finishExpressApplicationAFterNIBSign(Harness harness, String expectedState) {
        return start -> start
                .selectFromListOfRequests()
                .selectStateFilter("ROZPRACOVANÁ")
                .storeFirstApplicationId(harness)
                .selectFirstApplication()
                .clickOpenRequestDetail()
                .onWaitForModulationPage()
                .waitForModulation(180)
                .onModulationPage()
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onClientRequestPage()
                .clickCancelFilter()
                .checkApplicationState(harness.get(APPLICATION_ID_KEY), expectedState);
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withBusinessCreditConsolidation(Harness harness, String consolidationType, String dummyEmail, String loanConsolidationAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness(consolidationType)
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("nákup strojů, výrobních zařízení", loanConsolidationAmount))
                .clickContinue()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .clickAssociationFopNo()
                .clickNotTransformation()
                .then(smeAutomatSubTasks.editBusinessInformationGreenExpressBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.fillFinancialSignpostNettoIncome())
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onPrintInstructionPage()
                .clickRightButton()
                .then(smeAutomatSubTasks.waitForPreliminaryEvaluation(harness))
                .clickContinueToConsolidationCommitmentsPage()
                .addCommitmentManually()
                .then(smeAutomatSubTasks.setCommitment())
                .clickContinueToModulationPage()
                .waitForModulation(120)
                .onModulationPage()
                .clickCompleteCommitmentInfoButton()
                .onCompleteCommitmentsPage()
                .clickFirstCommitment()
                .clickEditCommitment()
                .then(smeAutomatSubTasks.fillCommitmentData())
                .clickContinueToModulationPage()
                .waitForModulation(120)
                .onModulationPage()
                .then(smeAutomatSubTasks.uploadScannedDocumentsConsolidation(harness));
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpresBusinessRetail(Harness harness, String dummyEmail, String loanExpresAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business Retail")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("nákup strojů, výrobních zařízení", loanExpresAmount))
                .clickContinue()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.fillFinancialSignpostNettoIncome())
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withGreenExpresBusiness(Harness harness, String dummyEmail, String loanGreenAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Zelený Expres Business")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("Zelené střechy", loanGreenAmount))
                .clickContinue()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickAddressSameAsPermanentResidence()
                .clickNotFamilyBusiness()
                .clickAssociationFopNo()
                .clickNotTransformation()
                .then(smeAutomatSubTasks.editBusinessInformationGreenExpressBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.assignDocuments("Čestné prohlášení Zelený EB", "Čestné prohlášení Zelený EB"))
                .then(smeAutomatSubTasks.assignDocuments("Projekt / Záměr / Smlouva", "Projekt / Záměr / Smlouva"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.zebAndEasiPrintRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpresBusinessEasi(Harness harness, String dummyEmail, String loanEasiAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business EIF EaSI")
                .then(smeAutomatSubTasks.fillRequiredLoanEb(loanEasiAmount))
                .clickContinue()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.assignDocuments("Čestné prohlášení EaSI", "Čestné prohlášení EaSI"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.zebAndEasiPrintRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocumentsEaSI(harness));
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withFlexiBusiness(Harness harness, String dummyEmail, String loanFlexiAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectFlexiBusiness("Flexi Business")
                .then(smeAutomatSubTasks.fillProductDetailsFlexiBusinessNoFopAssociation(loanFlexiAmount))
                .clickContinue()
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationFlexiBusiness())
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpresBusinessAndFlexiBusiness(Harness harness, String dummyEmail, String loanExpresAmount, String loanFlexiAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("nákup strojů, výrobních zařízení", loanExpresAmount))
                .clickContinue()
                .selectFlexiBusiness("Flexi Business")
                .then(smeAutomatSubTasks.fillProductDetailsFlexiBusinessNoFopAssociation(loanFlexiAmount))
                .clickContinue()
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationFlexiBusiness())
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostNettoIncome())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withReserveProBusiness(Harness harness, String dummyEmail, String loanReserveAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectFlexiBusiness("Rezerva PRO podnikání")
                .fillRequiredLoanAmount(loanReserveAmount)
                .clickNoFopAssociation()
                .clickContinue()
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationFlexiBusiness())
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withMonetaBusinessCard(Harness harness, String dummyEmail, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .then(addMonetaBusinessCard())
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotTransformation()
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .clickAssociationFopNo()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .then(smeAutomatSubTasks.sendDocumentsForMonetaBusinessCardIfPageShownOtherwiseSkip(harness));
    }


    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withMonetaBusinessCardAssociationFop(Harness harness, String dummyEmail, String lastYear, String yearBeforeLast, NonClient associatedMember) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .then(addMonetaBusinessCard())
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotTransformation()
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.setExpresBusinessDataWithAssociationFop())
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .continueToListOfPersonsOnRequestPage()
                .then(smeAutomatSubTasks.addAssociatedMember(associatedMember))
                .then(smeAutomatSubTasks.summarizeRequestAndPrintAssociation())
                .onSmeApplicationSignPage()
                .clickContinue()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .then(smeAutomatSubTasks.sendDocumentsForMonetaBusinessCardIfPageShownOtherwiseSkip(harness));
    }


    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withMonetaBusinessCardFamilyBusiness(Harness harness, String dummyEmail, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .then(addMonetaBusinessCard())
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotTransformation()
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.setExpresBusinessData())
                .clickFamilyBusiness()
                .fillOwnProfit("100")
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.fillPersonalFinancialData())
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .then(smeAutomatSubTasks.sendDocumentsForMonetaBusinessCardIfPageShownOtherwiseSkip(harness));
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withMonetaBusinessCardWithWife(Harness harness, String dummyEmail, String lastYear, String yearBeforeLast, NonClient wifeData) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .then(addMonetaBusinessCard())
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailAndMaritalStatus(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .continueToListOfPersonsOnRequestPage()
                .then(smeAutomatSubTasks.addHusbandOrWife(wifeData))
                .then(smeAutomatSubTasks.summarizeRequestAndPrint())
                .onRequestForSMEPage()
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .then(smeAutomatSubTasks.sendDocumentsForMonetaBusinessCardIfPageShownOtherwiseSkip(harness));
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withFlexiBusinessWithWife(Harness harness, String dummyEmail, String loanFlexiAmount, NonClient wifeData, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectFlexiBusiness("Flexi Business")
                .then(smeAutomatSubTasks.fillProductDetailsFlexiBusinessNoFopAssociation(loanFlexiAmount))
                .clickContinue()
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailAndMaritalStatus(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .continueToListOfPersonsOnRequestPage()
                .then(smeAutomatSubTasks.addHusbandOrWife(wifeData))
                .then(smeAutomatSubTasks.summarizeRequestAndPrint())
                .onRequestForSMEPage()
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpresBusinessWithWife(Harness harness, String dummyEmail, String loanExpresAmount, String lastYear, String yearBeforeLast, NonClient wifeData) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("nákup strojů, výrobních zařízení", loanExpresAmount))
                .clickContinue()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailAndMaritalStatus(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusiness())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.fillPersonalFinancialData())
                .then(smeAutomatSubTasks.fillFinancialSignpostNettoIncome())
                .continueToListOfPersonsOnRequestPage()
                .then(smeAutomatSubTasks.addHusbandOrWife(wifeData))
                .then(smeAutomatSubTasks.summarizeRequestAndPrint())
                .onRequestForSMEPage()
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withFlexiBusinessAssociationFop(Harness harness, String dummyEmail, String loanFlexiAmount, String lastYear, String yearBeforeLast, NonClient associatedMember) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectFlexiBusiness("Flexi Business")
                .then(smeAutomatSubTasks.fillProductDetailsFlexiBusinessYesFopAssociation(loanFlexiAmount))
                .clickContinue()
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailAndMaritalStatus(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationFlexiBusiness())
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .continueToListOfPersonsOnRequestPage()
                .then(smeAutomatSubTasks.addAssociatedMember(associatedMember))
                .then(smeAutomatSubTasks.summarizeRequestAndPrintAssociation())
                .onSmeApplicationSignPage()
                .clickContinue()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpressBusinessAssociationFop(Harness harness, String dummyEmail, String loanExpresAmount, String lastYear, String yearBeforeLast, NonClient associatedMember) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("nákup strojů, výrobních zařízení", loanExpresAmount))
                .clickContinue()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailAndMaritalStatus(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationExpresBusinessWithFopAssociation())
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .fillNettoIncomeOfHousehold("70000")
                .fillOtherLivingCosts("1000")
                .fillOtherMonthlyPayments("10000")
                .continueToListOfPersonsOnRequestPage()
                .then(smeAutomatSubTasks.addAssociatedMember(associatedMember))
                .then(smeAutomatSubTasks.summarizeRequestAndPrintAssociation())
                .onSmeApplicationSignPage()
                .clickContinue()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withFlexiBusinessFamilyBusiness(Harness harness, String dummyEmail, String loanFlexiAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectFlexiBusiness("Flexi Business")
                .then(smeAutomatSubTasks.fillProductDetailsFlexiBusinessNoFopAssociation(loanFlexiAmount))
                .clickContinue()
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationFlexiBusiness())
                .clickFamilyBusiness()
                .fillOwnProfit("75")
                .clickFamilyBusiness() //has to be here, because the fillOwnProfit has to be confirmed by clicking anywhere :D
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.fillPersonalFinancialData())
                .continueToListOfPersonsOnRequestPage()
                .then(smeAutomatSubTasks.summarizeRequestAndPrint())
                .onRequestForSMEPage()
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpresBusinessFamilyBusiness(Harness harness, String dummyEmail, String loanExpresAmount, String lastYear, String yearBeforeLast, String financingReason) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness(financingReason, loanExpresAmount))
                .clickContinue()
                .clickContinue()
                .onBusinessInfoPage()
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.setExpresBusinessData())
                .clickFamilyBusiness() //has to be here, because the fillOwnProfit has to be confirmed by clicking anywhere :D
                .fillOwnProfit("100")
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.fillPersonalFinancialData())
                .fillOtherLivingCosts("1000")
                .fillOtherMonthlyPayments("10000")
                .fillNettoIncomeOfHousehold("70000")
                .continueToListOfPersonsOnRequestPage()
                .then(smeAutomatSubTasks.summarizeRequestAndPrint())
                .onRequestForSMEPage()
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> withExpresBusinessAndFlexiBusinessAndMonetaBusinessCard(Harness harness, String dummyEmail, String loanExpresAmount, String loanFlexiAmount, String lastYear, String yearBeforeLast) {
        return start -> start
                .createNewProduct(HCisProductClass.SME_AUTOMATS)
                .then(smeAutomatSubTasks.selectSmeAutomatFop(harness))
                .selectExpresBusiness("Expres Business")
                .then(smeAutomatSubTasks.fillProductDetailsExpresBusiness("nákup strojů, výrobních zařízení", loanExpresAmount))
                .clickContinue()
                .selectFlexiBusiness("Flexi Business")
                .then(smeAutomatSubTasks.fillProductDetailsFlexiBusinessNoFopAssociation(loanFlexiAmount))
                .clickContinue()
                .onSelectProductsPage()
                .then(addMonetaBusinessCard())
                .onSelectProductsPage()
                .clickContinue()
                .then(smeAutomatSubTasks.sendDocumentationIfPageShownOtherwiseSkipFop(harness))
                .clickContinue()
                .onAdditionalBusinessData()
                .then(smeAutomatSubTasks.editEmailsToDummy(dummyEmail))
                .clickNotFamilyBusiness()
                .clickAddressSameAsPermanentResidence()
                .then(smeAutomatSubTasks.editBusinessInformationFlexiBusiness())
                .clickContinue()
                .onRequestedDocumentPage()
                .then(smeAutomatSubTasks.assignDocuments("Doklady FOP", "Živnostenský list / výpis z ŽR"))
                .then(smeAutomatSubTasks.selectNoPsdData())
                .then(smeAutomatSubTasks.fillFinancialSignpostDp(lastYear, yearBeforeLast))
                .then(smeAutomatSubTasks.fillFinancialSignpostNettoIncome())
                .then(smeAutomatSubTasks.continueToRequestPrint())
                .then(smeAutomatSubTasks.printRequest())
                .clickYes()
                .onWaitingForModulationPage()
                .then(smeAutomatSubTasks.waitForModulation(harness))
                .then(smeAutomatSubTasks.uploadScannedDocuments(harness))
                .then(smeAutomatSubTasks.sendDocumentsForMonetaBusinessCardIfPageShownOtherwiseSkip(harness));
    }

    public Function<KUL001_S001_SelectProductsPage, SIF004_S001_ContactSettingsForSendingEmailsPageTransitions> addMonetaBusinessCard() {
        return start -> start
                .selectProductToOnboard("Moneta Business Card")
                .clickAddProduct()
                .onCommercialCreditCardDetail()
                .then(smeAutomatSubTasks.fillCreditCardDetails())
                .then(smeAutomatSubTasks.fillContactSettings())
                .clickContinue();
    }


    public Function<BAL006_S002_ClientRequestPage, SMA002_S001_SMEAutomatsApplicationOverview> drawDownFeeExpresAndFlexiBusiness(Harness harness, String bankerName) {
        return start -> start
                .selectStateFilter("PODMÍNĚNÝ SOUHLAS")
                .selectProductFilter("Expres Business")
                .selectFirstApplication()
                .clickOpenRequestDetail()
                .onSMEAutomatsApplicationsOverview()
                .then(smeAutomatSubTasks.setParametersForExpresAndFlexiBusinessApplications(harness))
                .clickAcceptation()
                .clickAcceptationModalIfPresent()
                .then(smeAutomatSubTasks.waitForModulationIfPresent(120));
    }

    public Function<SMA002_S001_SMEAutomatsApplicationOverview, OBR003_S001_ClientContractSignPage> printAndSignExpresBusiness(Harness harness, String bankerName) {
        return start -> start
                .clickApplication("Expres Business")
                .clickPrintSignDeal()
                .onRequestedDocumentsPage()
                .clickContinue()
                .onClientContractSignPage()
                .clickRightButton()
                .onWaitingForModulationPage()
                .waitForModulation(180)
                .onBankerRepresentaionForVerification()
                .fillBankerName(bankerName)
                .clickSearchBanker()
                .clickContinue()
                .storeApplicationId(harness);
    }

    public Function<SMA002_S001_SMEAutomatsApplicationOverview, OBR003_S001_ClientContractSignPage> printAndSignFlexiBusiness(Harness harness, String bankerName) {
        return start -> start
                .clickApplication("Flexi Business")
                .clickPrintSignDeal()
                .onClientWarning()
                .clickCenterButton()
                .onRequestedDocumentsPage()
                .clickContinue()
                .onClientContractSignPage()
                .clickRightButton()
                .onWaitingForModulationPage()
                .waitForModulation(180)
                .onBankerRepresentaionForVerification()
                .fillBankerName(bankerName)
                .clickSearchBanker()
                .clickContinue()
                .storeApplicationId(harness);
    }

    public Function<HKO101_S001_MainClientPage, BAL006_S002_ClientRequestPage> drawDownFeeWithSignNIBExpresBusiness(Harness harness) {
        return start -> start
                .selectFromListOfRequests()
                .selectStateFilter("PODMÍNĚNÝ SOUHLAS")
                .selectProductFilter("Expres Business")
                .storeFirstApplicationId(harness)
                .selectFirstApplication()
                .clickOpenRequestDetail()
                .onSMEAutomatsApplicationsOverview()
                .then(smeAutomatSubTasks.setParametersForExpresBusinessApplication(harness))
                .clickApplication("Expres Business")
                .clickAcceptation()
                .clickAcceptationModalIfPresent()
                .then(smeAutomatSubTasks.waitForModulationIfPresent(120))
                .clickApplication("Expres Business")
                .clickPrintSignDeal()
                .onRequestedDocumentsPage()
                .selectAndAddDocument()
                .clickContinue()
                .onScanDocumentsPage()
                .uploadBusinessRegister()
                .selectFirstDocumentToAssign()
                .assignLoadedDocument()
                .clickContinue()
                .onClientContractSignPage()
                .clickCenterButton()
                .onCheckSigningPersonsEmail()
                .clickContinue()
                .waitForModulation(180)
                .onSendingDocumentsToIBSB()
                .clickSendToIBSB()
                .clickCenterButton()
                .onClientRequestPage();
    }

    public Function<OBR003_S001_ClientContractSignPage, BAL006_S002_ClientRequestPage> finishDrawingDown(Harness harness, String expectedState) {
        return start -> start
                .clickRightButton()
                .onClientContractSignPage()
                .checkSuccessfulVerification()
                .clickLeftButton()
                .onSignerSelection()
                .clickSignedAndContinueToPrintPage()
                .closePrintWindow()
                .onPrintPage()
                .closePrintWindow()
                .onSMESignedContractDocumentation()
                .clickSigned()
                .waitForModulation(120)
                .onClientContractSignPage()
                .checkSuccessfulyEstablishedProducts()
                .clickLeftButton()
                .onClientRequestPage()
                .clickCancelFilter()
                .checkApplicationState(harness.get(APPLICATION_ID_KEY), expectedState);

    }
}
