import { ScheduleType } from '../../../../AdaptableState/Common/Enums';
import StringExtensions from '../../../../Utilities/Extensions/StringExtensions';
export const isSettingsValid = (schedule, api) => {
    // Validate Name - mandatory and unique
    if (!schedule.Name?.trim()) {
        return 'A name is required.';
    }
    const allSchedules = api.scheduleApi.getSchedules();
    const isDuplicateName = allSchedules.some((s) => s.Name === schedule.Name && s.Uuid !== schedule.Uuid);
    if (isDuplicateName) {
        return 'A Schedule with this name already exists.';
    }
    if (schedule.ScheduleType === ScheduleType.Reminder) {
        const reminder = schedule;
        if (!reminder.MessageType) {
            return 'Please select a message type.';
        }
        if (StringExtensions.IsNullOrEmpty(reminder?.Header)) {
            return 'A reminder header is required.';
        }
        if (StringExtensions.IsNullOrEmpty(reminder?.Message)) {
            return 'A reminder message is required.';
        }
    }
    if (schedule.ScheduleType === ScheduleType.Report) {
        const report = schedule;
        if (StringExtensions.IsNullOrEmpty(report?.ReportName)) {
            return 'Please select a report.';
        }
        if (StringExtensions.IsNullOrEmpty(report?.ReportFormat)) {
            return 'Please select a report format.';
        }
    }
    if (schedule.ScheduleType === ScheduleType.ipushpull) {
        const ipushpull = schedule;
        if (StringExtensions.IsNullOrEmpty(ipushpull?.IPushPullReport?.ReportName)) {
            return 'Please select a report.';
        }
        if (StringExtensions.IsNullOrEmpty(ipushpull?.IPushPullReport?.Folder)) {
            return 'Please select a report folder.';
        }
        if (StringExtensions.IsNullOrEmpty(ipushpull?.IPushPullReport?.Page)) {
            return 'Please select a report page.';
        }
    }
    if (schedule.ScheduleType === ScheduleType.OpenFin) {
        const openfin = schedule;
        if (StringExtensions.IsNullOrEmpty(openfin?.OpenFinReport?.ReportName)) {
            return 'Please select a report.';
        }
    }
    return true;
};
