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.client.product.KOK701_S001_MeetingSchedulingPage;
import cz.moneta.test.dsl.util.DateFormatPatterns;
import cz.moneta.test.dsl.util.DateUtils;

import java.time.LocalDate;
import java.util.function.Function;

public class MeetingTasks {
    private final Harness harness;

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

    public Function<KOK701_S001_MeetingSchedulingPage, STS701_S002_ClientDetailPage> scheduleMeeting(String om, String meetingType, String product) {
        return page -> page
                .selectOM(om)
                .setMeetingType(meetingType)
                .setProduct(product)
                .setNotificationsToDoNotSend()
                .setMeetingToFirstWorkingDayOfNextMonth(getFirstWorkingDayMonthLater())
                // 1 - (neni), 2 - first real time slot
                .setMeetingTimeSlot(2)
                .confirmMeeting();
    }

    private String getFirstWorkingDayMonthLater() {
        LocalDate meetingDate = LocalDate.now().plusMonths(1);
        while (!DateUtils.isWorkingDay(meetingDate)) {
            meetingDate = meetingDate.plusDays(1);
        }
        return DateUtils.getDateWithFormat(meetingDate, DateFormatPatterns.IB_DATE_FORMAT);
    }
}
