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

import cz.moneta.test.dsl.ufo.banka.pages.fon.DMS070_S001_ScanDocumentsPage;
import cz.moneta.test.dsl.ufo.banka.pages.income.Extend_FinancialIncomePageForPo;
import cz.moneta.test.dsl.ufo.banka.pages.income.FIN001_S001_FinancialIncomeSummaryPage;
import cz.moneta.test.dsl.ufo.banka.pages.income.FIN002_S002_FinancialIncomePage;
import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;

import java.util.function.Function;

public class IncomeModuleTasks {
    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> fillIncomeModuleFop(String lastYear, String yearBeforeLast) {
        return start -> start
                .openIncomeModule()
                .clickAddFinancialStatement()
                .then(fillTaxReturnDataFop(lastYear))
                .then(scanDocumentsFop())
                .clickAddFinancialStatement()
                .then(fillTaxReturnDataFop(yearBeforeLast))
                .then(scanDocumentsFop())
                .backToMainClientPage();
    }

    public Function<HKO101_S001_MainClientPage, HKO101_S001_MainClientPage> fillIncomeModulePo(String lastYear, String yearBeforeLast) {
        return start -> start
                .openIncomeModule()
                .then(fillTaxReturnDataPo(lastYear))
                .then(scanDocumentsPo())
                .then(fillTaxReturnDataPo(yearBeforeLast))
                .then(scanDocumentsPo())
                .backToMainClientPage();
    }

    public Function<FIN001_S001_FinancialIncomeSummaryPage, DMS070_S001_ScanDocumentsPage> fillTaxReturnDataPo(String incomeDate) {
        return start -> start
                .clickAddFinancialStatement()
                .clickPaperFormForPo()
                .fillIncomeDate(incomeDate)
                .onNewFinancialIncomePo()
                .then(fillAssets())
                .then(fillLiabilities())
                .then(fillProfitLossStatements())
                .clickVerified()
                .clickTaxAdvisorNo()
                .clickContinue()
                .fillTaxToPay("0")
                .clickOnIncomeModuleLabel()
                .continueToScanDocumentsPage();
    }

    public Function<Extend_FinancialIncomePageForPo, Extend_FinancialIncomePageForPo> fillAssets() {
        return start -> start
                .fillUnderOrOverpayment("0")
                .fillSubscribedCapital("2000000")
                .fillCurrentAssets("2000000")
                .fillLongtermProperty("1000000")
                .fillAssetAccruals("1000000");
    }

    public Function<Extend_FinancialIncomePageForPo, Extend_FinancialIncomePageForPo> fillLiabilities() {
        return start -> start
                .fillOwnCapital("1000000")
                .fillReserves("1000000")
                .fillLongtermObligations("1000000")
                .fillShorttermObligations("1000000")
                .fillAccruedLiabilitiesCiii("1000000")
                .fillAccruedLiabilities("1000000");
    }

    public Function<Extend_FinancialIncomePageForPo, Extend_FinancialIncomePageForPo> fillProfitLossStatements() {
        return start -> start
                .fillProductsServicesRevenue("1000000")
                .fillGoodsRevenue("0")
                .fillPerformanceConsumption("0")
                .fillStorageChange("0")
                .fillActivationInput("0")
                .fillPersonalCosts("0")
                .fillOperatingAreaEditingValues("0")
                .fillOtherOperatingIncome("1000000")
                .fillOtherOperatingCosts("0")
                .fillOperatingProfit("2000000")
                .fillEconomyResultAfterTax("500000")
                .fillSharesTransferToPartners("0")
                .fillAccountingPeriodEconomyResult("500000");
    }

    public Function<FIN002_S002_FinancialIncomePage, DMS070_S001_ScanDocumentsPage> fillTaxReturnDataFop(String incomeDate) {
        return start -> start
                .selectTypeOfIncome("Výdaje % z příjmů")
                .clickPaperFormForFop()
                .fillIncomeDate(incomeDate)
                .selectNumberOfMonths("12")
                .clickTaxAdvisorNo()
                .onNewFinancialIncomeFop()
                .fillAllEmployersIncomeSummary("0")
                .fillMandatoryInsuranceSummary("0")
                .fillTaxPayedAbroad("0")
                .fillPartialTaxBase("0")
                .fillPartialTaxBaseOrLoss("0")
                .fillTaxAfterDiscount("0")
                .fillTaxToPay("0")
                .fillIncome("2000000")
                .fillExpensesRelatedToIncome("500000")
                .fillDifferenceIncomeExpenditure("1500000")
                .fillPartialTaxBaseLoss("0")
                .fillIncomeFromRent("0")
                .fillCosts("0")
                .fillIncomeCostsDifferenceBeforeTax("0")
                .clickVerified()
                .clickContinue()
                .fillTaxAfterDiscount("0")
                .fillTaxToPay("0")
                .clickOnIncomeModuleLabel()
                .continueToScanDocumentsPage();
    }

    public Function<DMS070_S001_ScanDocumentsPage, FIN001_S001_FinancialIncomeSummaryPage> scanDocumentsFop() {
        return start -> start
                .uploadAndAssignFakeDP()
                .clickContinue()
                .onFinancialIncomeSummaryPage();
    }

    public Function<DMS070_S001_ScanDocumentsPage, FIN001_S001_FinancialIncomeSummaryPage> scanDocumentsPo() {
        return start -> start
                .uploadAndAssignFakeDP()
                .reloadPage()
                .uploadAndAssignFakeBalanceSheet()
                .reloadPage()
                .uploadAndAssignFakeIncomeModule()
                .clickContinue()
                .onFinancialIncomeSummaryPage();
    }

}
