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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.common.pages.TIS046_S001_DocumentsProvidedToClientPage;
import cz.moneta.test.dsl.ufo.banka.pages.fon.TIS050_S001_SignerSelectionPage;
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.main.codelists.Product;
import cz.moneta.test.dsl.ufo.banka.tasks.accountenums.CurrentAccountsEnum;
import cz.moneta.test.dsl.ufo.banka.tasks.accountenums.SavingsAccountsEnum;
import cz.moneta.test.dsl.util.data.client.NonClient;

import java.util.function.Function;

public class NewPackagedProductTasks {

    private final Harness harness;

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

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> ibWithMobileKeyAndCurrentAccount(NonClient nonClient, CurrentAccountsEnum feePlan) {
        return start -> start.createNewProduct(HCisProductClass.CURRENT_ACCOUNT)
                .onCurrentAccountPage()
                .selectFeePlan(feePlan.getAccountName())
                .selectDistributionType("Elektronicky IB")
                .clickDispositionRadioYes()
                .clickConfirm()
                .onElectronicDistributionChannelCreationPage()
                .selectDistributionChannel("IB Heslo/MK")
                .clickContinueDismissAlertIfPresent()
                .onSignerSelectionPage()
                .clickSignedPersonallyPhysicallyAndContinue()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
                .onPrintInstructionPage()
                .clickRightButton()
                .onAccountDispositionOwnerPage()
                .clickNotCreateNow()
                .clickSkipCreate()
                .onAddCodeOfRecommendedPersonPage()
                .checkProductNotRecommended()
                .clickWithoutRecommendationAndDismissAlertIfvisible()
                .onIbTypeSelectionPage()
                .clickActiveToIbPage()
                //.insertEnvelopeNumber()
                .enterMobilePhoneNumber(nonClient.mobileNumber())
                .clickContinueToSettingADCPage()
                .clickSave()
                .onDispositionGeneratePage()
                .clickGenerateLater()
                .onContractDocumentationPage()
                .clickContinueSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(Product.ADC_IB_MK_ACTIVE.getValue());
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> ibWithMobileKeyAndCurrentAccountAfterSearchCif(String mobileNumber, CurrentAccountsEnum feePlan) {
        return start -> start.then(selectsAndFillsPageToCreateIbWithMobileKeyAndCurrentAccount(feePlan))
                .clickSignedPersonallyPhysicallyAndContinue()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onDocumentsProvidedToClientPage()
                .then(finishCreateIbWithMobileKeyAndCurrentAccount(mobileNumber));
    }

    private Function<HKO101_S001_MainClientPage, TIS050_S001_SignerSelectionPage> selectsAndFillsPageToCreateIbWithMobileKeyAndCurrentAccount(CurrentAccountsEnum feePlan) {
        return start -> start.createNewProduct(HCisProductClass.CURRENT_ACCOUNT)
                .onCurrentAccountPage()
                .selectFeePlan(feePlan.getAccountName())
                .selectDistributionType("Elektronicky IB")
                .clickDispositionRadioNo()
                .clickConfirm()
                .onElectronicDistributionChannelCreationPage()
                .selectDistributionChannel("IB Heslo/MK")
                .clickContinueDismissAlertIfPresent()
                .onSignerSelectionPage();
    }

    private Function<TIS046_S001_DocumentsProvidedToClientPage, HKO101_S001_MainClientPage> finishCreateIbWithMobileKeyAndCurrentAccount(String mobileNumber) {
        return start -> start.clickContinue()
                .onIbSettingsPage()
                .clickActiveOperation()
                .fillDailyLimit("50000")
                .fillWeeklyLimit("0")
                .clickContinue()
                .clickModalWarningContinue()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
                .onSettingAdcPage()
                .clickSaveAndAcceptAlert()
                .onPrintInstructionPage()
                .clickCenterButton()
                .onDispositionGeneratePage()
                .clickGenerateNow()
                .onPrintPage()
                .closePrintWindow()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(Product.ADC_IB_MK_ACTIVE.getValue());
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> createNewCurrentAccountGeniusGoldWithSavingsAccountGold() {
        String feePlanCurrentAccount = CurrentAccountsEnum.GENIUS_GOLD.getAccountName();
        String feePlanSavingAccount = SavingsAccountsEnum.GOLD.getAccountName();
        return start -> start.createNewProduct(HCisProductClass.CURRENT_ACCOUNT)
                .onCurrentAccountPage()
                .selectFeePlan(feePlanCurrentAccount)
                .clickDispositionRadioYes()
                .clickConfirm()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
                .onAccountDispositionOwnerPage()
                .clickOwnerOnly()
                .onPrintSignPadPage()
                .clickBack()
                .clickCenterButton()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onDocumentsProvidedToClientPage()
                .clickContinue()
                .onSavingAccountConfirmation()
                .clickContinue()
                .clickNotCreateNow()
                .clickSkipCreate()
                .onAddCodeOfRecommendedPersonPage()
                .checkProductNotRecommended()
                .clickWithoutRecommendationAndDismissAlertIfvisible()
                .onPrintInstructionPage()
                .clickCenterButton()
                .onDispositionGeneratePage()
                .clickGenerateNow()
                .onPrintPage()
                .closePrintWindow()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onSummaryStartDocumentsPage()
                .storeCurrentAccountNumber()
                .logSavingAccountGoldNumber()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(feePlanCurrentAccount)
                .checkProductActive(feePlanSavingAccount);
    }
}