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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.OPN008_S001_SignContractPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.consolidation.UDC003_S001_CommitmentsToConsolidationPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.consolidation.UDC006_S001_ConsolidationScoringPage;
import cz.moneta.test.dsl.util.code.lists.HCisAllStavZadosti;

import java.util.function.Function;

import static cz.moneta.test.dsl.ufo.banka.pages.loans.PopCheckboxes.*;
import static cz.moneta.test.dsl.ufo.banka.pages.main.codelists.HCisProductClass.CONSOLIDATION;
import static cz.moneta.test.dsl.ufo.banka.pages.search.HLO001_S001_ClientSearchPage.BANKER_NAME;

public class NewConsolidationTasks {

    private final Harness harness;

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

    public Function<HKO101_S001_MainClientPage, UDC003_S001_CommitmentsToConsolidationPage> createNewConsolidationRequestToScoring() {
        return start -> start.createNewProduct(CONSOLIDATION)
                .onConsolidationPage()
                .typeIntoTotalLoanAmount("80000")
                .typeIntoRequiredIncrease("20000")
                .selectNumberOfInstallments("60")
                .clickCalculationOfPaymentButton()
                .clickContinueButtonToDocumentPage()
                .selectIdCardRadio()
                .selectDriverLicenceRadio()
                .clickDocumentsCheckAndContinue()
                .onCreditCardApplicantPage()
                .selectMaritalStatusVerificationSource("údaj z OP")
                .fillMobileNumberEmployment("420724282023")
                .selectNoticePeriod("Ne")
                .selectTrialPeriod("Ne")
                .fillIncomeSourceCount(1)
                .fillNetMonthlyIncome(60000)
                .fillHouseholdIncome(60000)
                .fillMonthlyPayments(0)
                .fillAllowances(0)
                .fillOtherExpenses(0)
                .clickTelcoYes()
                .selectOccupation("manager/ředitel")
                .selectPOP("Potvrzení o příjmu")
                .clickPopCheckbox(SIGNED)
                .clickPopCheckbox(BIRTHNUMBER)
                .clickPopCheckbox(NO_DEPENDANTS)
                .clickPopCheckbox(AGE)
                .clickPopCheckbox(EMPLOYER_STAMP)
                .clickPoPContinue()
                .clickContinue()
                .onPromoCodePage()
                .checkProductNotRecommended()
                .clickWithoutRecommendation()
                .onSignatureConfirmationPage()
                .clickApplicantSignatureCheckbox()
                .clickYes()
                .onScanDocumentsPage()
                .clickSkipButton()
                .onCommitmentsToConsolidationPage();
    }

    public Function<UDC003_S001_CommitmentsToConsolidationPage, UDC006_S001_ConsolidationScoringPage> createNewConsolidationRequestAfterScoring(HCisAllStavZadosti expectedAppStat) {
        return start -> start.clickAddSfCommitmentButton()
                .selectInstallmentCompanyName("COFIDIS s.r.o.")
                .selectCommitmentType("Úvěr")
                .typeIntoAmountToBePaid(25000)
                .typeIntoMonthlyInstallmentAmount(3000)
                .clickAddButtonAndDismissPopupWindow()
                .clickContinueButtonToConsolidationCommitmentsPage()
                .clickContinueButtonToSigningConfirmationPage()
                .clickConfirmCheckBox()
                .clickYesButtonAndSendToApproval()
                .waitForStatusAndRefresh(expectedAppStat.getValue());
    }

    public Function<UDC006_S001_ConsolidationScoringPage, UDC006_S001_ConsolidationScoringPage> createNewConsolidationRequestConditionalAgreement(HCisAllStavZadosti expectedAppStat) {
        return start -> start.clickConditionalAgreementButton()
                .clickPreApprovedCombinationAndVariantsProposedButton()
                .clickEstablishScoringButton()
                .typeIntoTotalLoanAmount(80000)
                .clickPaymentCalculationButton()
                .clickContinueButtonToApplicantPage()
                .fillIncomeSourceCount(1)
                .fillNetMonthlyIncome(60000)
                .fillHouseholdIncome(60000)
                .fillMonthlyPayments(0)
                .fillAllowances(0)
                .fillOtherExpenses(0)
                .clickTelcoYes()
                .selectPOP("Potvrzení o příjmu")
                .clickPopCheckbox(SIGNED)
                .clickPopCheckbox(BIRTHNUMBER)
                .clickPopCheckbox(NO_DEPENDANTS)
                .clickPopCheckbox(AGE)
                .clickPopCheckbox(EMPLOYER_STAMP)
                .clickPoPContinue()
                .clickContinue()
                .onLoanConsolidationCommitmentsPage()
                .clickRadioButtonAndEditButton()
                .selectInstallmentCompanyName("COFIDIS s.r.o.")
                .selectEvidenceOfCommitmentExistence("Smlouva o úvěru")
                .typeIntoLoanAgreementNumber(123456)
                .typeIntoLoanAccountForPayment(17225118)
                .typeIntoBankCode("0100")
                .selectProofOfRepayment("Výpis z běžného účtu")
                .typeIntoAnnualInterestRate(8)
                .typeIntoAmountToPay(4500)
                .clickSaveButtonToConsolidationScoringPage()
                .clickContinueToSignaturePage()
                .clickApplicantSignatureCheckbox()
                .clickYes()
                .onScanDocumentsPage()
                .clickSkipButtonAndStayOnPage()
                .clickSkipButton()
                .onScoringPage()
                .continueToLoanConsolidationScoringPage()
                .storeAppId()
                .waitForStatusAndRefresh(expectedAppStat.getValue());
    }

    public Function<UDC006_S001_ConsolidationScoringPage, OPN008_S001_SignContractPage> createNewConsolidationAccountsFoundation() {
        return start -> start.clickAccountFoundationButton()
                .clickFirstVariant()
                .clickSelect()
                .onPreContractualInfromationPrintedPag()
                .clickContinueButtonToDraftContractCopyPage()
                .clickContinue()
                .onSecondBankerJoiningPage()
                .fillSurnameInput(harness.get(BANKER_NAME))
                .clickContinue()
                .onLetterPrintPage()
                .clickSendButton()
                .clickOkButton()
                .clickOkAndContinueToDocumentsScanPage()
                .clickSkipButton()
                .onApprovedConsolidationPrintPage()
                .dismissPopupWindow()
                .clickContinueButton()
                .clickFirstSignerCheckbox()
                .dismissPopupWindow();
        //pokračovat podpisem druhého bankéře
    }

    public Function<OPN008_S001_SignContractPage, UDC006_S001_ConsolidationScoringPage> createNewConsolidationAccountsFoundationFinish(String status) {
        return start -> start.clickControlButton()
                .clickConfirmButton()
                .clickContinueButton()
                .onConsolidationScoringPage()
                .checkStatus(status);
    }
}