package cz.moneta.test.dsl.util.task.ufo.operations;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
import cz.moneta.test.dsl.ufo.operations.search.OPS001_S001_ClientSearchPageUfoOperations;
import cz.moneta.test.dsl.ufo.operations.search.SearchBy;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.ETS701_S001_ClientDocuments;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.OTP701_S001_UniversalPrintProcessPage;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.PSP701_S004_PrintTemplatePage;
import cz.moneta.test.dsl.util.DateUtils;

import java.util.function.Function;

import static cz.moneta.test.dsl.ufo.operations.ufoOperations.PSP701_S004_PrintTemplatePage.ATTACHMENT_PATH;

public class PrintTemplateTasks {

    private final Harness harness;

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

    public Function<OPS001_S001_ClientSearchPageUfoOperations, PSP701_S004_PrintTemplatePage> createPrintTemplateWithCif(String cif, String department, String category, String printName) {
        return start -> start
                .fillSearchInput(cif)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .clickPrintLettersWithCif()
                .selectDepartment(department)
                .selectCategory(category)
                .selectTemplate(printName)
                .selectGenderIfVisible()
                .clickPrint();
    }

    public Function<OPS001_S001_ClientSearchPageUfoOperations, PSP701_S004_PrintTemplatePage> createPrintTemplateWithAccount(String account, String department, String category, String printName) {
        return start -> start
                .fillSearchInput(account)
                .searchBy(SearchBy.ACCOUNT_NUMBER)
                .onClientDetailsPage()
                .clickPrintLettersWithAccount()
                .selectDepartment(department)
                .selectCategory(category)
                .selectTemplate(printName)
                .selectGenderIfVisible()
                .clickPrint();
    }

    public Function<OTP701_S001_UniversalPrintProcessPage, ETS701_S001_ClientDocuments> createPrintTemplateInteractive(String department, String category, String printName, String title) {
        return start -> start
                .selectDepartment(department)
                .selectCategory(category)
                .selectTemplate(printName)
                .clickPrintInteractive()
                .clickOk()
                .clickComplete()
                .assertHistory("Historie")
                .switchToModalWindowByTitle(title)
                .clickCorrespondence()
                .assertPrintName(printName)
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    public Function<STS701_S002_ClientDetailPage, PSP701_S004_PrintTemplatePage> createManualLetter() {
        return start -> start
                .clickCorrespondence()
                .clickManualSend()
                .selectCompany("MONETA Money Bank")
                .clickContinue()
                .selectLetter("Sdělení klientovi")
                .uploadAttachment(ATTACHMENT_PATH)
                .clickSave();
    }

}