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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.*;
import cz.moneta.test.dsl.ufo.banka.pages.cards.debit.HPO009_S001_DebitCardDetailPage;
import cz.moneta.test.dsl.ufo.banka.pages.cards.debit.OBR003_S001_ClientContractSignPageTransitions;
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.fon.CIF113_S001_ChangeDataFO;
import cz.moneta.test.dsl.ufo.banka.pages.fon.TIS050_S001_SignerSelectionPage;
import cz.moneta.test.dsl.ufo.banka.pages.loans.VER017_S001_SecondBankerVerificationStatusPage;
import cz.moneta.test.dsl.ufo.banka.pages.loans.creditCard.NKK006_S001_CreditCardScoringResultPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
import cz.moneta.test.dsl.ufo.banka.pages.search.CIF013_S002_ClientNotFoundPage;
import cz.moneta.test.dsl.ufo.banka.pages.search.HLO001_S001_ClientSearchPage;
import cz.moneta.test.dsl.util.BankaUtils;
import cz.moneta.test.dsl.util.data.client.AccommodationType;
import cz.moneta.test.dsl.util.data.client.EducationLevel;
import cz.moneta.test.dsl.util.data.client.MaritalStatus;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.Lookup;

import java.util.function.Function;

import static cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage.CLIENT_ID_KEY;
import static cz.moneta.test.dsl.ufo.banka.pages.main.PSP004_S001_PrintPage.DOCUMENT_URLS_STORE_KEY;

public class CardsServicingTasks {

    private final Harness harness;

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

    public CreditCardsTasks creditCards() {
        return new CreditCardsTasks(harness);
    }

    public static final String DISPOSITION_DOCUMENT_NAME = "Dispozice";

    public static final String CONTRACT_DOCUMENT_NAME = "Smlouva";

    public static final String RECORD_FROM_MEETING_DOCUMENT_NAME = "ZZJ";

    public static final String AGREEMENT_WITH_TRAVEL_INSURANCE_DOCUMENT_NAME = "Souhlas s cestovním pojištěním";

    public static final String PRECONTRACT_DOCUMENT_NAME = "Předběžná smlouva";

    public static final String SERVICE_INFORMATION_DOCUMENT_NAME = "Servisní infromace";


    public String getPrintedPages() {
        return "Url dokumentů: \n" + BankaUtils.formatDocumentUrlsWithNames(harness.get(DOCUMENT_URLS_STORE_KEY, true));
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> cancelDebitCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPageAndCloseAlertIfPresent()
                .clickCardCancellation()
                .selectReasonToCancel(2)
                .clickCardReturned()
                .clickCancelPK()
                .clickGenerateLater()
                .onDebitCardDetailPage()
                .clickBackToClient();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> activateDebitCard(String cardNumber) {
        return start -> start
                .storeClientIdNumber()
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .assertCardStatus("Neaktivní")
                .clickCardActivation()
                .selectIdCardType("OP")
                .fillIdCardNumberWithPossibleAlert(harness.get(CLIENT_ID_KEY))
                .clickActivateCard()
                .onSignerSelectionPageForDebitCards()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onDebitCardDetailPage()
                .clickBackToClient();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> activateCreditCard(String cardNumber) {
        return start -> start
                .storeClientIdNumber()
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .clickActivateCard()
                .onCreditCardActivation()
                .selectIdCardType("OP")
                .fillIdCardNumberFromStored(harness.get(CLIENT_ID_KEY))
                .clickActivateCard()
                .onSignerSelectionPageForDebitCards()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onCreditCardDetailPage()
                .clickBackToClient();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> checkDebitCardIsActive(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .assertCardStatus("Aktivní");
    }

    public Function<HKO101_S001_MainClientPage, OBR001_S001_PrintInstructionPageTransitions> changeLimitOnDebitCardMainPart(String cardNumber, String intLimitExpected, String atmLimitExpected, String posLimitExpected) {

        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .storeLimits(harness)
                .clickChangeOfData()
                .changePosLimit("100000000")
                .clickSaveFalse()
                .dismissAlert()
                .changeAtmLimit("100000000")
                .clickSaveFalse()
                .dismissAlert()
                .changeIntLimit("100000000")
                .clickSaveFalse()
                .dismissAlert()
                .checkAndChangeLimits(atmLimitExpected, intLimitExpected, posLimitExpected, harness)
                .clickSaveTrue()
                .clickLeftButton();
    }

    public Function<OBR001_S001_PrintInstructionPageTransitions, HPO009_S001_DebitCardDetailPage> changeLimitOnDebitCardLastPart(Harness harness) {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, TIS050_S001_SignerSelectionPage.CONTINUE_BUTTON, Lookup.ID)) {
            return start -> start
                    .onSignerPage()
                    .clickSignedPersonallyPhysicallyAndContinue()
                    .onDebitCardDetailPage();
        } else {
            return start -> start.onDebitCardDetailPage();
        }
    }

    public Function<HKO101_S001_MainClientPage, HPO019_S001_CreditCardDetailPage> changeLimitRetailSmartCreditCard(String cardNumber, String intLimitExpected, String atmLimitExpected, String motoLimitExpected) {

        return start -> start
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .storeLimits(harness)
                .clickCardService()
                .clickDailyLimits()
                .changeMotoLimit("100000000")
                .changeLimitsWithAlert()
                .changeAtmLimit("100000000")
                .changeLimitsWithAlert()
                .changeIntLimit("100000000")
                .changeLimitsWithAlert()
                .checkAndChangeLimits(atmLimitExpected, intLimitExpected, motoLimitExpected, harness)
                .changeLimits()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onCreditCardSignConfirmation()
                .clickSignConfirmed()
                .onCreditCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO039_S001_MbcDetailPage> changeLimitMBC(String cardNumber, String intLimitExpected, String atmLimitExpected, String motoLimitExpected) {

        return start -> start
                .clickActiveProduct(cardNumber)
                .onMBCDetailPage()
                .storeLimits(harness)
                .clickChangeLimits()
                .changeMotoLimit("100000000")
                .changeLimitsWithAlert()
                .changeAtmLimit("100000000")
                .changeLimitsWithAlert()
                .changeIntLimit("100000000")
                .changeLimitsWithAlert()
                .checkAndChangeLimits(atmLimitExpected, intLimitExpected, motoLimitExpected, harness)
                .changeLimits()
                .clickSignedAndContinueToPrintPage()
                .saveDocumentUrl(DISPOSITION_DOCUMENT_NAME)
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onMbcDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> changeIntMotoTransactionsRetailDebitCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickMotoInt()
                .clickInternetAndMotoChange(harness)
                .clickToSignerSelectionPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickLeftButton()
                .onDebitCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> changeDccSettingOnRetailDebitCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickMotoInt()
                .clickDccChange(harness)
                .clickToSignerSelectionPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickLeftButton()
                .onDebitCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> changeIntMotoTransactionsCommercialDebitCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickMotoInt()
                .clickInternetAndMotoChange(harness)
                .clickToPrint()
                .saveDocumentUrl(DISPOSITION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickLeftButton()
                .onDebitCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> changeDccSettingOnCommercialDebitCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickMotoInt()
                .clickDccChange(harness)
                .clickToPrint()
                .saveDocumentUrl(DISPOSITION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickLeftButton()
                .onDebitCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO019_S001_CreditCardDetailPage> changeDccSettingOnRetailCreditCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .clickMotoInt()
                .clickDccChange(harness)
                .clickToSignerSelectionPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickLeftButton()
                .onCreditCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO039_S001_MbcDetailPage> changeDccSettingOnMBC(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onMBCDetailPage()
                .clickChangeMotoInt()
                .clickDccChange(harness)
                .clickToPrint()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickLeftButton()
                .onMbcDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO019_S001_CreditCardDetailPage> changeIntMotoTransactionsRetailCreditCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .clickMotoInt()
                .clickInternetAndMotoChange(harness)
                .clickToSignerSelectionPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickLeftButton()
                .onCreditCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO039_S001_MbcDetailPage> changeIntMotoTransactionsMBC(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onMBCDetailPage()
                .clickChangeMotoInt()
                .clickInternetAndMotoChange(harness)
                .clickToPrint()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickLeftButton()
                .onMbcDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> change3dSecureNumberRetailDebitCard(String cardNumber) {
        return start -> start
                .storeClientIdNumber()
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .click3dSecureChange()
                .selectDocumentType(2)
                .fillDocumentNumberFromHko(harness)
                .fillNew3dSecureNumber()
                .clickToChange3dSecureNumber()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onDebitCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> change3dSecureNumberCommercialDebitCard(String cardNumber) {
        return start -> start
                .storeClientIdNumber()
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .click3dSecureChange()
                .selectDocumentType(2)
                .fillDocumentNumberFromHko(harness)
                .fillNew3dSecureNumber()
                .clickToChange3dSecureNumberToPrint()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onDebitCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO019_S001_CreditCardDetailPage> change3dSecureNumberRetailCreditCard(String cardNumber) {
        return start -> start
                .storeClientIdNumber()
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .clickCardService()
                .clickContactMobileNumber()
                .clickO2Operator()
                .clickProductToChange3dSecureNum(cardNumber)
                .clickSend()
                .selectDocumentType(2)
                .fillDocumentNumberFromHko(harness)
                .fillNew3dSecureNumber()
                .clickToChange3dSecureNumber()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onCreditCardSignConfirmation()
                .clickSignConfirmed()
                .onCreditCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO039_S001_MbcDetailPage> change3dSecureNumberMbc(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onMBCDetailPage()
                .clickServiceOperations()
                .clickContactMobileNumberForMbc()
                .fillNew3dSecureNumber()
                .clickToChange3dSecureNumberToSignerPage()
                .clickSignedAndContinueToPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .onMbcDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> change3dSecureNumberChildCard(String cardNumber, String childIdCardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .click3dSecureChange()
                .selectDocumentType(2)
                .fillDocumentNumber(childIdCardNumber)
                .fillNew3dSecureNumber()
                .clickToChange3dSecureNumber()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onChildCardConfirmationPage()
                .clickSignConfirmed();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> temporarilyBlockRetailDebitCard(String cardNumber, String time) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickBlockMenu()
                .clickTemporarilyBLock()
                .clickOwner()
                .fillDate()
                .fillTime(time)
                .fillTellNum("720961931")
                .clickPrintToSignerPageWithPossibleAlert()
                .onSignerSelectionPageForRetail()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(DISPOSITION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickCenterButton()
                .onDebitCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, POZ001_S007_CreditCardServiceOperationsPage> temporarilyBlockRetailCreditCard(String cardNumber, String time) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .clickCardServiceWithPossibleAlert()
                .clickBlockMenu()
                .selectBlockingReason("Dočasná blokace")
                .fillDate()
                .fillTime(time)
                .fillTellNum("720961931")
                .clickBlockCreditCardToSignerPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(DISPOSITION_DOCUMENT_NAME)
                .closePrintWindow()
                .onCreditCardSignConfirmation()
                .clickSignConfirmed()
                .onCreditCardServiceOperationsPage();
    }

    public Function<HKO101_S001_MainClientPage, POZ001_S007_CreditCardServiceOperationsPage> temporarilyBlockMBC(String cardNumber, String time) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onMBCDetailPage()
                .clickServiceOperations()
                .clickBlockMenu()
                .selectBlockingReason("Dočasná blokace")
                .fillDate()
                .fillTime(time)
                .fillTellNum("720961931")
                .clickBlockCardToSignerPage()
                .clickSignedAndContinueToPrintPage()
                .saveDocumentUrl(DISPOSITION_DOCUMENT_NAME)
                .closePrintWindow()
                .onCreditCardSignConfirmation()
                .clickSignConfirmed()
                .onPrintInstructionPage()
                .clickRightButton()
                .onCreditCardServiceOperationsPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> temporarilyBlockCommercialDebitCard(String cardNumber, String time) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickBlockMenu()
                .clickTemporarilyBLock()
                .clickOwner()
                .fillDate()
                .fillTime(time)
                .fillTellNum("720961931")
                .clickPrintToSignerPageWithPossibleAlert()
                .onSignerSelectionPageForCommercial()
                .clickSignedAndContinueToPrintPage()
                .saveDocumentUrl(DISPOSITION_DOCUMENT_NAME)
                .closePrintWindow()
                .onContractSignPage()
                .clickCenterButton()
                .onDebitCardDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> permaBlockCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickBlockMenu()
                .clickLostReport()
                .clickOwner()
                .fillDescription("AUTOMAT TEST")
                .fillCity("Praha")
                .clickPrintToSignerPageWithPossibleAlert()
                .onSignerSelectionPageForRetail()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onBlockMenu()
                .clickSave();
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> changeName(String lastName) {
        return start -> start
                .clickEdit()
                .onChangeDataFO()
                .changeLastName(lastName)
                .updateIDValidation("1.1.2028", "1.1.2028")
                .clickSend()
                .onChangeOfIdentificationDocuments()
                .clickNo()
                .onSignerSelectionPage()
                .clickContinue()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onContinueAfterSigning()
                .clickContinueToSettingADC()
                .clickSaveAndAcceptAlert()
                .onMainClientPage()
                .clickActiveProduct("PK")
                .onDebitCardDetailPage()
                .checkLastName(lastName);
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> setUpPIM() {
        return start -> start
                .clickEdit()
                .onChangeDataFO()
                .clickEditIncome()
                .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("76235700")
                .clickSearchCompanyButton()
                .clickFirstResult()
                .clickSelectEmployerButton()
                .clickNoticePeriodNoRadio()
                .clickTrialPeriodNoRadio()
                .clickIncomeCashNoRadio()
                .fillEmploymentStartDate("1.1.2000")
                .fillPhoneCountryCode("420")
                .fillPhoneNumber("737111000")
                .fillNetIncome(100000)
                .clickAcceptIncomeButtonAndDisableAlertIfVisible()
                .clickBackButton()
                .onChangeDataFO()
                .clickBack()
                .onMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, CIF113_S001_ChangeDataFO> confirmPIM() {
        return start -> start
                .clickEdit()
                .onChangeDataFO()
                .clickEditIncome()
                .clickNoticePeriodNoRadio()
                .clickTrialPeriodNoRadio()
                .clickIncomeCashNoRadio()
                .clickAcceptIncomeButton()
                .clickBackButton()
                .onChangeDataFO();
    }

    public Function<HLO001_S001_ClientSearchPage, HLO001_S001_ClientSearchPage> secondBankerApplicationSign(String applicationID, String clientID) {
        return start -> start
                .clickSecondSignature()
                .fillApplicationId(applicationID)
                .clickSecondSignatureButton()
                .fillIdNumber(clientID)
                .clickVerify()
                .clickOkAndCloseWindow();
    }

    public Function<HLO001_S001_ClientSearchPage, OBR003_S001_ClientContractSignPageTransitions> secondBankerApplicationRetailSign() {
        return start -> start
                .clickVerificationLoan()
                .clickFirstApplication()
                .confirmDocumentsAndSaveDecision()
                .clickLeftButton();
    }

    public Function<OBR001_S001_PrintInstructionPageTransitions, HPO009_S001_DebitCardDetailPage> generatePinDCLastPart(Harness harness) {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, OBR001_S001_PrintInstructionPage.CENTER_BUTTON, Lookup.ID)) {
            return start -> start
                    .onPrintInstructionPage()
                    .clickCenterButton()
                    .onDebitCardDetailPage();
        } else {
            return start -> start.onDebitCardDetailPage();
        }
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> generatePinForRetailDebitCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickGeneratePinButton()
                .clickPinOnMobileNumber()
                .clickMobileNumberFromCif()
                .clickSaveOnSignerSelectionPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .then(generatePinDCLastPart(harness));
    }

    public Function<POZ001_S009_ServiceOperationsCreditCardSignConfirmationTransitions, HPO019_S001_CreditCardDetailPage> generatePinCCLastPart(Harness harness) {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, OBR001_S001_PrintInstructionPage.CENTER_BUTTON, Lookup.ID)) {
            return start -> start
                    .onPrintInstructionPage()
                    .clickCenterButton()
                    .onCreditCardDetailPage();
        } else {
            return start -> start.onCreditCardDetailPage();
        }
    }

    public Function<HKO101_S001_MainClientPage, HPO019_S001_CreditCardDetailPage> generatePinForRetailCreditCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .clickCardService()
                .clickGeneratePin()
                .clickContinue()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onCreditCardSignConfirmation()
                .clickSignConfirmed()
                .then(generatePinCCLastPart(harness));
    }

    public Function<HKO101_S001_MainClientPage, HPO009_S001_DebitCardDetailPage> generatePinForCommercialDebitCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onDebitCardDetailPage()
                .clickGeneratePinButton()
                .clickPinOnMobileNumber()
                .clickMobileNumberFromCif()
                .clickSaveOnPrintInstructionPage()
                .clickRightButton()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignerPage()
                .clickRightButton()
                .then(generatePinDCLastPart(harness));
    }

    public Function<HKO101_S001_MainClientPage, HPO039_S001_MbcDetailPage> generatePinForMBC(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onMBCDetailPage()
                .clickServiceOperations()
                .clickGeneratePin()
                .clickContinueToFopSingerSelectionPage()
                .clickSignedAndContinueToPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onCreditCardSignConfirmation()
                .clickSignConfirmed()
                .onPrintInstructionPage()
                .clickCenterButton()
                .onMbcDetailPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> cancelOldRequestIfPossible() {
        return start -> start
                .selectFromListOfRequests()
                .selectFirstApplication()
                .clickOpenRequestDetail()
                .onCreditCardScoringResultPage()
                .then(cancelRequestIfPossible())
                .clickEndToClientRequestPage()
                .onClientRequestPage()
                .clickBackToMainClientPage();
    }

    public Function<NKK006_S001_CreditCardScoringResultPage, NKK006_S001_CreditCardScoringResultPage> cancelRequestIfPossible() {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementEnabled(NKK006_S001_CreditCardScoringResultPage.CANCEL_BUTTON)) {
            return start -> start.clickCancel()
                    .onRequestCancellationPage()
                    .selectCancellationReason("Stornováno ze strany klienta")
                    .clickConfirmButtonToSignerSelectionPage()
                    .clickSignedPersonallyWithPossiblePhysicalSignature()
                    .onPrintPage()
                    .closePrintWindow()
                    .onPrintInstructionPage()
                    .clickLeftButton()
                    .onCreditCardScoringResultPage();
        } else {
            return null;
        }
    }


    public Function<HKO101_S001_MainClientPage, NKK007_S001_ClipRequestPageTransitionPage> clipRetailCreditCardBeforeSecondBankerPartOne(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .clickClipCard()
                .selectIdCardRadio()
                .selectPassportRadio()
                .clickDocumentsCheckButton()
                .clickContinue()
                .onCreditCardApplicantPage()
                .fillHouseholdIncome(150000)
                .fillPaymentsOutsideMMB(0)
                .fillOtherMonthlyExpenses(1)
                .selectFirstIncome()
                .clickContinueToClipRequest()
                .getAndFillEditedHigherAmount()
                .clickContinueToTransitionPage();
    }

    public Function<NKK007_S001_ClipRequestPageTransitionPage, VER017_S001_SecondBankerVerificationStatusPage> clipRetailCreditCardBeforeSecondBankerFinalPart(Harness harness) {
        UfoEndpoint endpoint = harness.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, NKK007_S005_FormalCheckPage.FORMAL_CHECK_PAGE_ID_XPATH, Lookup.XPATH)) {
            return start -> start.onFormalCheckPage()
                    .then(this.clipRetailCreditCardPotentialFormalError())
                    .then(this.clipRetailCreditCardBeforeSecondBankerPartTwo());
        } else {
            return start -> start.onPrintInstructions()
                    .then(this.clipRetailCreditCardBeforeSecondBankerPartTwo());
        }
    }

    public Function<NKK007_S005_FormalCheckPage, OBR001_S001_PrintInstructionPageTransitions> clipRetailCreditCardPotentialFormalError() {
        return start -> start.clickFix()
                .fillHouseholdIncome(150000)
                .fillPaymentsOutsideMMB(0)
                .fillOtherMonthlyExpenses(1)
                .selectFirstIncome()
                .clickContinueToClipRequest()
                .getAndFillEditedHigherAmount()
                .clickContinueToTransitionPage()
                .onPrintInstructions()
                .clickRightButton();
    }

    public Function<OBR001_S001_PrintInstructionPage, VER017_S001_SecondBankerVerificationStatusPage> clipRetailCreditCardBeforeSecondBankerPartTwo() {
        return start -> start.clickRightButton()
                .onSignerPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(SERVICE_INFORMATION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignaturePage()
                .clickApplicantSignatureCheckbox()
                .clickYes()
                .onInstructionPage()
                .clickCenterButton()
                .onScoringPage()
                .waitForLoader()
                .onCreditCardScoringResultPage()
                .waitForStatusAndRefresh("SOUHLAS")
                .clickCreateProductAndPrintContract()
                .onSecondBankerSearch()
                .fillSurnameInput(harness.getGlobal("BANKER_NAME"))
                .clickSearch()
                .selectFirstName()
                .clickContinue()
                .onSecondBankerVerificationPage();
    }

    public Function<HKO101_S001_MainClientPage, NKK006_S001_CreditCardScoringResultPage> clipRetailCreditCardAfterSecondBanker() {
        return start -> start
                .selectFromListOfRequests()
                .selectFirstApplication()
                .clickOpenRequestDetail()
                .onCreditCardScoringResultPage()
                .clickCreateProductAndPrintContract()
                .onSecondBankerVerificationStatusPage()
                .clickContinue()
                .onSignerSelectionPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(CONTRACT_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignContractPage()
                .clickFirstSignerCheckbox()
                .clickYesButtonToClientContractSignPage()
                .clickLeftButton()
                .onCreditCardScoringResultPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> declipRetailCreditCard(String cardNumber) {
        return start -> start
                .clickActiveProduct(cardNumber)
                .onCreditCardDetailPage()
                .storeCreditCardTotalCredit()
                .clickDeclipCard()
                .getAndFillEditedLowerAmount(harness)
                .clickSelectFirstCard()
                .fillNewLimits("1000", "1000", "1000")
                .clickChangeLimits()
                .clickContinueToScoringPage()
                .waitForLoader()
                .onCreditCardScoringResultPage()
                .waitForStatusAndRefresh("SOUHLAS")
                .clickCreateProductAndPrintContract()
                .onSingerPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .saveDocumentUrl(DISPOSITION_DOCUMENT_NAME)
                .closePrintWindow()
                .onSignContractPage()
                .clickFirstSignerCheckbox()
                .clickYesButtonToClientContractSignPage()
                .clickLeftButton()
                .onCreditCardScoringResultPage()
                .clickEnd();
    }

    public static NonClient setUpChild(Harness harness, String childBirthNumber) {
        return harness.data().newNonClient()
                .withBirthNumber(childBirthNumber)
                .withEmail("dummy.A4@moneta.cz")
                .withMobileNumber("737111000")
                .withIdNumber("44672289")
                .withIdNumberExpiration("13.9.2028")
                .withMaritalStatus(MaritalStatus.SINGLE)
                .withAccommodationType(AccommodationType.PARENTS)
                .withDependants(0)
                .withEducationLevel(EducationLevel.BASIC);
    }

    public Function<CIF013_S002_ClientNotFoundPage, HKO101_S001_MainClientPage> createNewChildCif(NonClient nonClient, String firstParentName, String lastParentName, String parentBirthNumber, String dateOfParentBirth) {
        return start -> start
                .clickCreateNewCustomer()
                .clickCif()
                .clickCzechNationality()
                .clickContinue()
                .onTabletCommunicationErrorPage()
                .continueToSignError()
                .clickCenterButton()
                .onCreateNewCif()
                .fillFirstAndLastNames(nonClient.firstName(), nonClient.lastName())
                .fillIdCardNumber(nonClient.idCardNumber())
                .clickContinue()
                .onNotREgisteredWarning()
                .clickCenterButton()
                .onStatutoryAuthorityPage()
                .clickAdd()
                .onLegalRepesenatitveAddPage()
                .selectLegalRepresentative("RODIČE")
                .clickContinue()
                .typeLastName(lastParentName)
                .typeFirstName(firstParentName)
                .typeBirthNumber(parentBirthNumber)
                .typeDateOfBirthNumber(dateOfParentBirth)
                .clickCzechNationalityButton()
                .clickContinue()
                .clickCenterButton()
                .onChangeDataFO()
                .clickSend()
                .onIncomeEditPage()
                .clickAcceptIncomeButtonAndDisableAlertIfVisible()
                .clickBackButton()
                .onPrintInstructionPage()
                .clickLeftButton()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickLeftButton()
                .onStatutoryAuthorityPage()
                .clickContinue()
                .onNewCifPage()
                .tryCloseIdentificationPopup()
                .fillPersonalIdentificationData()
                .clickBornInCzechButton()
                .fillPlaceOfBirth(nonClient.placeOfBirth())
                .clickToCzechRepublicNationality()
                .fillResidency()
                .fillStreet(nonClient.residencyAddress().getStreet())
                .fillStreetNumber(nonClient.residencyAddress().getDescriptiveNumber())
                .fillStreetOrientationNumber(nonClient.residencyAddress().getOrientationNumber())
                .fillCity(nonClient.residencyAddress().getCity())
                .fillZip(nonClient.residencyAddress().getZip())
                .clickResidencyInCzechRepublic()
                .fillPersonalIdentificationData()
                .selectToEducationLevel(nonClient.educationLevel().getUfoValue())
                .fillContacts()
                .fillEmail(nonClient.email())
                .fillHomePhone(nonClient.fixPhoneNumberHome())
                .fillMobilePhonePrefix("420")
                .fillMobilePhone(nonClient.mobileNumber())
                .fillIdentificationDocuments()
                .fillFirstIdNumber(nonClient.idCardNumber())
                .clickAddSecondId()
                .selectSecondId("Rodný list")
                .fillSecondIdNumber("12345678")
                .fillSecondIdValidity("31.12.2049")
                .selectSecondIdAuthorities("Česká republika")
                .clickConsents()
                .clickContinue()
                .onClientContractSignPage()
                .clickLeftButton()
                .onAmlSurveyPage()
                .clickEnd()
                .onSignerSelectionPage()
                .clickSignedPersonallyWithPossiblePhysicalSignature()
                .onPrintPage()
                .closePrintWindow()
                .onPrintInstructionPage()
                .clickRightButton()
                .onDocumentScanPage()
                .clickSkipButton()
                .onClientContractSignPage()
                .clickCenterButton()
                .onMainClientPage();
    }
}