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

import cz.moneta.test.dsl.ufo.banka.pages.cards.debit.OBR003_S001_ClientContractSignPage;
import cz.moneta.test.dsl.ufo.banka.pages.fon.DMS070_S001_ScanDocumentsPage;
import cz.moneta.test.dsl.ufo.banka.pages.fop.*;
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.util.data.client.NonClient;

import java.util.function.Function;

public class NewAcceleratedFopClientTasks {

    public Function<CIF013_S002_ClientNotFoundPage, HKO101_S001_MainClientPage> createAcceleratedFopCif(NonClient nonClient) {
        return start -> start
                .clickCreateAcceleratedFop()
                .then(fillBasicBusinessData(nonClient))
                .then(uploadScannedDocuments())
                .then(fillIdentificationFopData(nonClient))
                .then(fillPersonalAndContactData(nonClient))
                .then(checkAntiLaunderingStatements())
                .then(printRequest())
                .clickRightButton()
                .onWaitingForModulationPage()
                .waitForModulation(30)
                .onClientContractSignPage()
                .clickLeftButton()
                .onMainClientPage();
    }

    public Function<CIF069_S001_CreateNewAcceleratedCifPage, DMS070_S001_ScanDocumentsPage> fillBasicBusinessData(NonClient nonClient) {
        return start -> start
                .fillCompanyName(nonClient.fullName())
                .clickMagnifyingGlass()
                .typeAddress("Vyskočilova 1b")
                .clickSearchForAddress()
                .clickFirstFoundAddressAndConfirm()
                .clickCzechFlagForBusinessAddress()
                .fillBusinessFoundedDate("2.2.2013")
                .fillLegalForm("101")
                .fillOkecCode("239100")
                .selectEconomicalSector("Osoby samostatně výdělečně činné")
                .clickCzechFlagEstablishment()
                .clickCzechFlagTaxResidency()
                .selectNumberOfEmployees("žádný")
                .continueToScanDocumentsPage();
    }

    public Function<DMS070_S001_ScanDocumentsPage, CIF070_S001_IdentificationDataPage> uploadScannedDocuments() {
        return start -> start
                .uploadAndAssignFakeRegisterRecord()
                .saveUploadedDocument()
                .clickContinue()
                .onIdentificationDataPage();
    }

    public Function<CIF070_S001_IdentificationDataPage, CIF071_S001_PersonalAndContactDataPage> fillIdentificationFopData(NonClient nonClient) {
        return start -> start
                .fillFirstName(nonClient.firstName())
                .fillLastName(nonClient.lastName())
                .fillBirthDate(nonClient.birthDate())
                .fillBirthPlace(nonClient.placeOfBirth())
                .clickCzechCountryOfBirth()
                .fillIdValidTill(nonClient.idNumberExpiration())
                .fillIdNumber(nonClient.idNumber())
                .fillBirthNumber(nonClient.birthNumber())
                .fillIdControlNumber("0")
                .clickMagnifyingGlass()
                .typeAddress("Vyskočilova 1b")
                .clickSearchForAddress()
                .clickFirstFoundAddressAndConfirm()
                .clickCzechFlagPermanentResidency()
                .fillActualResidencySince("2.3.2015")
                .clickMaleGender()
                .selectSecondId("ŘP")
                .fillSecondIdNumber(nonClient.driverLicenceId())
                .fillSecondIdValidTill(nonClient.drivingLicenceExpiration())
                .clickCzechFlagSecondId()
                .clickGdprCheckbox()
                .continueToPersonalAndContactDataPage();
    }

    public Function<CIF071_S001_PersonalAndContactDataPage, CIF072_S001_AntiLaunderingStatementPage> fillPersonalAndContactData(NonClient nonClient) {
        return start -> start
                .selectMaritalStatus(nonClient.maritalStatus().getUfoValue())
                .selectEducationLevel(nonClient.educationLevel().getUfoValue())
                .selectAccommodationType(nonClient.accommodationType().getUfoValue())
                .fillNumberOfDependents(String.valueOf(nonClient.dependants()))
                .fillCompanyEmail(nonClient.email())
                .fillCompanyMobile("420" + nonClient.mobileNumber())
                .fillPersonalEmail(nonClient.email())
                .fillPersonalMobile("420" + nonClient.mobileNumber())
                .clickAcceptConsents()
                .continueToAntiLaunderingStatementPage();
    }

    public Function<CIF072_S001_AntiLaunderingStatementPage, CIF074_S001_AcceleratedFopCifSummary> checkAntiLaunderingStatements() {
        return start -> start
                .clickCashlessTransaction()
                .selectCurrencyMajority("CZK")
                .clickNoForeignTransactionsSend()
                .clickNoForeignTransactionsReceive()
                .clickNoLoansExpected()
                .clickNoMoreThanHalf()
                .selectLastTurnover("1 000 000 - 2 999 999 Kč")
                .selectMmbTurnover("1 000 000 - 2 999 999 Kč")
                .clickNoPoliticallyExposedPerson()
                .continueToAcceleratedFopCifSummary();
    }

    public Function<CIF074_S001_AcceleratedFopCifSummary, OBR003_S001_ClientContractSignPage> printRequest() {
        return start -> start
                .continueToModulationPage()
                .onPrintPage()
                .saveDocumentUrl()
                .closePrintWindow()
                .onClientContractSignPage();
    }
}
