package cz.moneta.test.dsl.hypos.tasks;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.hypos.pages.contract.EditContinuePage;
import cz.moneta.test.dsl.hypos.pages.hypokom.HypokomSearchPage;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.data.hypos.HyposContract;

import java.util.function.Function;

import static cz.moneta.test.dsl.hypos.enums.HyposLogType.TASK;
import static cz.moneta.test.dsl.hypos.tasks.HyposTasks.defaultDateFormat;

public class HypokomTasks {
    private final Harness harness;
    private HyposCommonTasks tasks;

    public HypokomTasks(Harness harness) {
        this.harness = harness;
        this.tasks = harness.tasks().hypos().hyposCommonTasks();
    }

    public Function<HypokomSearchPage, HypokomSearchPage> searchClientByContractId(String contractId) {
        tasks.hyposLog(TASK, new Object(){}.getClass().getEnclosingMethod().getName());
        return start -> start.fillHyposId(contractId)
                .clickFilterButton();
    }

    public Function<HypokomSearchPage, HypokomSearchPage> setClientAppointmentDate() {
        tasks.hyposLog(TASK, new Object(){}.getClass().getEnclosingMethod().getName());
        return start -> start.clickElaborateContactButton()
                .clickConditionsAndSymptomsTab()
                .fillFlagDate(DateUtils.getFormattedTodayDate(defaultDateFormat))
                .clickSetButtonAndDismissAlert()
                .clickCloseButton();
    }

    public Function<HypokomSearchPage, EditContinuePage> createNewContract(String contractId, HyposContract hyposContract) {
        tasks.hyposLog(TASK, new Object(){}.getClass().getEnclosingMethod().getName());
        return start -> start.clickCreateContractButtonAndSwitch()
                .checkAgreements(hyposContract)
                .clickAresAndJustice()
                .clickEstablishContract()
                .checkEnterContractButtonExistence()
                .checkContractId(contractId);
    }
}