"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSettingsValid = void 0;
const tslib_1 = require("tslib");
const Enums_1 = require("../../../../AdaptableState/Common/Enums");
const StringExtensions_1 = tslib_1.__importDefault(require("../../../../Utilities/Extensions/StringExtensions"));
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 === Enums_1.ScheduleType.Reminder) {
        const reminder = schedule;
        if (!reminder.MessageType) {
            return 'Please select a message type.';
        }
        if (StringExtensions_1.default.IsNullOrEmpty(reminder?.Header)) {
            return 'A reminder header is required.';
        }
        if (StringExtensions_1.default.IsNullOrEmpty(reminder?.Message)) {
            return 'A reminder message is required.';
        }
    }
    if (schedule.ScheduleType === Enums_1.ScheduleType.Report) {
        const report = schedule;
        if (StringExtensions_1.default.IsNullOrEmpty(report?.ReportName)) {
            return 'Please select a report.';
        }
        if (StringExtensions_1.default.IsNullOrEmpty(report?.ReportFormat)) {
            return 'Please select a report format.';
        }
    }
    if (schedule.ScheduleType === Enums_1.ScheduleType.ipushpull) {
        const ipushpull = schedule;
        if (StringExtensions_1.default.IsNullOrEmpty(ipushpull?.IPushPullReport?.ReportName)) {
            return 'Please select a report.';
        }
        if (StringExtensions_1.default.IsNullOrEmpty(ipushpull?.IPushPullReport?.Folder)) {
            return 'Please select a report folder.';
        }
        if (StringExtensions_1.default.IsNullOrEmpty(ipushpull?.IPushPullReport?.Page)) {
            return 'Please select a report page.';
        }
    }
    if (schedule.ScheduleType === Enums_1.ScheduleType.OpenFin) {
        const openfin = schedule;
        if (StringExtensions_1.default.IsNullOrEmpty(openfin?.OpenFinReport?.ReportName)) {
            return 'Please select a report.';
        }
    }
    return true;
};
exports.isSettingsValid = isSettingsValid;
