"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReminderScheduleSuspend = exports.ReminderScheduleDelete = exports.ReminderScheduleEdit = exports.ReminderScheduleAdd = exports.ReportScheduleUnSuspendAll = exports.ReportScheduleSuspendAll = exports.ReportScheduleUnSuspend = exports.ReportScheduleSuspend = exports.ReportScheduleDelete = exports.ReportScheduleEdit = exports.ReportScheduleAdd = exports.OpenFinScheduleUnSuspendAll = exports.OpenFinScheduleSuspendAll = exports.OpenFinScheduleUnSuspend = exports.OpenFinScheduleSuspend = exports.OpenFinScheduleDelete = exports.OpenFinScheduleEdit = exports.OpenFinScheduleAdd = exports.ScheduleReady = exports.ScheduleJobRun = exports.SCHEDULE_READY = exports.OPENFIN_SCHEDULE_UNSUSPEND_ALL = exports.OPENFIN_SCHEDULE_SUSPEND_ALL = exports.OPENFIN_SCHEDULE_UNSUSPEND = exports.OPENFIN_SCHEDULE_SUSPEND = exports.OPENFIN_SCHEDULE_DELETE = exports.OPENFIN_SCHEDULE_EDIT = exports.OPENFIN_SCHEDULE_ADD = exports.IPUSHPULL_SCHEDULE_UNSUSPEND_ALL = exports.IPUSHPULL_SCHEDULE_SUSPEND_ALL = exports.IPUSHPULL_SCHEDULE_UNSUSPEND = exports.IPUSHPULL_SCHEDULE_SUSPEND = exports.IPUSHPULL_SCHEDULE_DELETE = exports.IPUSHPULL_SCHEDULE_EDIT = exports.IPUSHPULL_SCHEDULE_ADD = exports.REMINDER_SCHEDULE_UNSUSPEND_ALL = exports.REMINDER_SCHEDULE_SUSPEND_ALL = exports.REMINDER_SCHEDULE_UNSUSPEND = exports.REMINDER_SCHEDULE_SUSPEND = exports.REMINDER_SCHEDULE_DELETE = exports.REMINDER_SCHEDULE_EDIT = exports.REMINDER_SCHEDULE_ADD = exports.REPORT_SCHEDULE_UNSUSPEND_ALL = exports.REPORT_SCHEDULE_SUSPEND_ALL = exports.REPORT_SCHEDULE_UNSUSPEND = exports.REPORT_SCHEDULE_SUSPEND = exports.REPORT_SCHEDULE_DELETE = exports.REPORT_SCHEDULE_EDIT = exports.REPORT_SCHEDULE_ADD = exports.SCHEDULE_JOB_RUN = void 0;
exports.ScheduleReducer = exports.IPushPullScheduleUnSuspendAll = exports.IPushPullScheduleSuspendAll = exports.IPushPullScheduleUnSuspend = exports.IPushPullScheduleSuspend = exports.IPushPullScheduleDelete = exports.IPushPullScheduleEdit = exports.IPushPullScheduleAdd = exports.ReminderScheduleUnSuspendAll = exports.ReminderScheduleSuspendAll = exports.ReminderScheduleUnSuspend = void 0;
const tslib_1 = require("tslib");
const GeneralConstants_1 = require("../../Utilities/Constants/GeneralConstants");
const AdaptableHelper_1 = tslib_1.__importDefault(require("../../Utilities/Helpers/AdaptableHelper"));
const utils_1 = require("./utils");
/**
 * @ReduxAction Runs a Scheduled job
 */
exports.SCHEDULE_JOB_RUN = 'SCHEDULE_JOB_RUN';
/**
 * @ReduxAction A Report Schedule has been added
 */
exports.REPORT_SCHEDULE_ADD = 'REPORT_SCHEDULE_ADD';
/**
 * @ReduxAction A Report Schedule has been edited
 */
exports.REPORT_SCHEDULE_EDIT = 'REPORT_SCHEDULE_EDIT';
/**
 * @ReduxAction A Report Schedule has been deleted
 */
exports.REPORT_SCHEDULE_DELETE = 'REPORT_SCHEDULE_DELETE';
/**
 * @ReduxAction A Report Schedule has been suspended
 */
exports.REPORT_SCHEDULE_SUSPEND = 'REPORT_SCHEDULE_SUSPEND';
/**
 * @ReduxAction A Report Schedule has been unsuspended or activated
 */
exports.REPORT_SCHEDULE_UNSUSPEND = 'REPORT_SCHEDULE_UNSUSPEND';
/**
 * @ReduxAction All Report Schedules have been suspended
 */
exports.REPORT_SCHEDULE_SUSPEND_ALL = 'REPORT_SCHEDULE_SUSPEND_ALL';
/**
 * @ReduxAction All Report Schedules have been unsuspended or activated
 */
exports.REPORT_SCHEDULE_UNSUSPEND_ALL = 'REPORT_SCHEDULE_UNSUSPEND_ALL';
/**
 * @ReduxAction A Reminder Schedule has been added
 */
exports.REMINDER_SCHEDULE_ADD = 'REMINDER_SCHEDULE_ADD';
/**
 * @ReduxAction A Reminder Schedule has been edited
 */
exports.REMINDER_SCHEDULE_EDIT = 'REMINDER_SCHEDULE_EDIT';
/**
 * @ReduxAction A Reminder Schedule has been deleted
 */
exports.REMINDER_SCHEDULE_DELETE = 'REMINDER_SCHEDULE_DELETE';
/**
 * @ReduxAction A Reminder Schedule has been suspended
 */
exports.REMINDER_SCHEDULE_SUSPEND = 'REMINDER_SCHEDULE_SUSPEND';
/**
 * @ReduxAction A Reminder Schedule has been unsuspended or activated
 */
exports.REMINDER_SCHEDULE_UNSUSPEND = 'REMINDER_SCHEDULE_UNSUSPEND';
/**
 * @ReduxAction All Reminder Schedules have been suspended
 */
exports.REMINDER_SCHEDULE_SUSPEND_ALL = 'REMINDER_SCHEDULE_SUSPEND_ALL';
/**
 * @ReduxAction All Reminder Schedules have been unsuspended or activated
 */
exports.REMINDER_SCHEDULE_UNSUSPEND_ALL = 'REMINDER_SCHEDULE_UNSUSPEND_ALL';
exports.IPUSHPULL_SCHEDULE_ADD = 'IPUSHPULL_SCHEDULE_ADD';
exports.IPUSHPULL_SCHEDULE_EDIT = 'IPUSHPULL_SCHEDULE_EDIT';
exports.IPUSHPULL_SCHEDULE_DELETE = 'IPUSHPULL_SCHEDULE_DELETE';
exports.IPUSHPULL_SCHEDULE_SUSPEND = 'IPUSHPULL_SCHEDULE_SUSPEND';
exports.IPUSHPULL_SCHEDULE_UNSUSPEND = 'IPUSHPULL_SCHEDULE_UNSUSPEND';
exports.IPUSHPULL_SCHEDULE_SUSPEND_ALL = 'IPUSHPULL_SCHEDULE_SUSPEND_ALL';
exports.IPUSHPULL_SCHEDULE_UNSUSPEND_ALL = 'IPUSHPULL_SCHEDULE_UNSUSPEND_ALL';
exports.OPENFIN_SCHEDULE_ADD = 'OPENFIN_SCHEDULE_ADD';
exports.OPENFIN_SCHEDULE_EDIT = 'OPENFIN_SCHEDULE_EDIT';
exports.OPENFIN_SCHEDULE_DELETE = 'OPENFIN_SCHEDULE_DELETE';
exports.OPENFIN_SCHEDULE_SUSPEND = 'OPENFIN_SCHEDULE_SUSPEND';
exports.OPENFIN_SCHEDULE_UNSUSPEND = 'OPENFIN_SCHEDULE_UNSUSPEND';
exports.OPENFIN_SCHEDULE_SUSPEND_ALL = 'OPENFIN_SCHEDULE_SUSPEND_ALL';
exports.OPENFIN_SCHEDULE_UNSUSPEND_ALL = 'OPENFIN_SCHEDULE_UNSUSPEND_ALL';
/**
 * @ReduxAction Schedule Module is ready
 */
exports.SCHEDULE_READY = 'SCHEDULE_READY';
const ScheduleJobRun = (schedule, scheduleType) => ({
    type: exports.SCHEDULE_JOB_RUN,
    schedule,
    scheduleType,
});
exports.ScheduleJobRun = ScheduleJobRun;
const ScheduleReady = (scheduleState) => ({
    type: exports.SCHEDULE_READY,
    scheduleState,
});
exports.ScheduleReady = ScheduleReady;
const OpenFinScheduleAdd = (openFinSchedule) => ({
    type: exports.OPENFIN_SCHEDULE_ADD,
    openFinSchedule,
});
exports.OpenFinScheduleAdd = OpenFinScheduleAdd;
const OpenFinScheduleEdit = (openFinSchedule) => ({
    type: exports.OPENFIN_SCHEDULE_EDIT,
    openFinSchedule,
});
exports.OpenFinScheduleEdit = OpenFinScheduleEdit;
const OpenFinScheduleDelete = (openFinSchedule) => ({
    type: exports.OPENFIN_SCHEDULE_DELETE,
    openFinSchedule,
});
exports.OpenFinScheduleDelete = OpenFinScheduleDelete;
const OpenFinScheduleSuspend = (openFinSchedule) => ({
    type: exports.OPENFIN_SCHEDULE_SUSPEND,
    openFinSchedule,
});
exports.OpenFinScheduleSuspend = OpenFinScheduleSuspend;
const OpenFinScheduleUnSuspend = (openFinSchedule) => ({
    type: exports.OPENFIN_SCHEDULE_UNSUSPEND,
    openFinSchedule,
});
exports.OpenFinScheduleUnSuspend = OpenFinScheduleUnSuspend;
const OpenFinScheduleSuspendAll = () => ({
    type: exports.OPENFIN_SCHEDULE_SUSPEND_ALL,
});
exports.OpenFinScheduleSuspendAll = OpenFinScheduleSuspendAll;
const OpenFinScheduleUnSuspendAll = () => ({
    type: exports.OPENFIN_SCHEDULE_UNSUSPEND_ALL,
});
exports.OpenFinScheduleUnSuspendAll = OpenFinScheduleUnSuspendAll;
// Report
const ReportScheduleAdd = (reportSchedule) => ({
    type: exports.REPORT_SCHEDULE_ADD,
    reportSchedule,
});
exports.ReportScheduleAdd = ReportScheduleAdd;
const ReportScheduleEdit = (reportSchedule) => ({
    type: exports.REPORT_SCHEDULE_EDIT,
    reportSchedule,
});
exports.ReportScheduleEdit = ReportScheduleEdit;
const ReportScheduleDelete = (reportSchedule) => ({
    type: exports.REPORT_SCHEDULE_DELETE,
    reportSchedule,
});
exports.ReportScheduleDelete = ReportScheduleDelete;
const ReportScheduleSuspend = (reportSchedule) => ({
    type: exports.REPORT_SCHEDULE_SUSPEND,
    reportSchedule,
});
exports.ReportScheduleSuspend = ReportScheduleSuspend;
const ReportScheduleUnSuspend = (reportSchedule) => ({
    type: exports.REPORT_SCHEDULE_UNSUSPEND,
    reportSchedule,
});
exports.ReportScheduleUnSuspend = ReportScheduleUnSuspend;
const ReportScheduleSuspendAll = () => ({
    type: exports.REPORT_SCHEDULE_SUSPEND,
});
exports.ReportScheduleSuspendAll = ReportScheduleSuspendAll;
const ReportScheduleUnSuspendAll = () => ({
    type: exports.REPORT_SCHEDULE_UNSUSPEND,
});
exports.ReportScheduleUnSuspendAll = ReportScheduleUnSuspendAll;
const ReminderScheduleAdd = (reminderSchedule) => ({
    type: exports.REMINDER_SCHEDULE_ADD,
    reminderSchedule,
});
exports.ReminderScheduleAdd = ReminderScheduleAdd;
const ReminderScheduleEdit = (reminderSchedule) => ({
    type: exports.REMINDER_SCHEDULE_EDIT,
    reminderSchedule,
});
exports.ReminderScheduleEdit = ReminderScheduleEdit;
const ReminderScheduleDelete = (reminderSchedule) => ({
    type: exports.REMINDER_SCHEDULE_DELETE,
    reminderSchedule,
});
exports.ReminderScheduleDelete = ReminderScheduleDelete;
const ReminderScheduleSuspend = (reminderSchedule) => ({
    type: exports.REMINDER_SCHEDULE_SUSPEND,
    reminderSchedule,
});
exports.ReminderScheduleSuspend = ReminderScheduleSuspend;
const ReminderScheduleUnSuspend = (reminderSchedule) => ({
    type: exports.REMINDER_SCHEDULE_UNSUSPEND,
    reminderSchedule,
});
exports.ReminderScheduleUnSuspend = ReminderScheduleUnSuspend;
const ReminderScheduleSuspendAll = () => ({
    type: exports.REMINDER_SCHEDULE_SUSPEND_ALL,
});
exports.ReminderScheduleSuspendAll = ReminderScheduleSuspendAll;
const ReminderScheduleUnSuspendAll = () => ({
    type: exports.REMINDER_SCHEDULE_UNSUSPEND_ALL,
});
exports.ReminderScheduleUnSuspendAll = ReminderScheduleUnSuspendAll;
const IPushPullScheduleAdd = (iPushPullSchedule) => ({
    type: exports.IPUSHPULL_SCHEDULE_ADD,
    iPushPullSchedule,
});
exports.IPushPullScheduleAdd = IPushPullScheduleAdd;
const IPushPullScheduleEdit = (iPushPullSchedule) => ({
    type: exports.IPUSHPULL_SCHEDULE_EDIT,
    iPushPullSchedule,
});
exports.IPushPullScheduleEdit = IPushPullScheduleEdit;
const IPushPullScheduleDelete = (iPushPullSchedule) => ({
    type: exports.IPUSHPULL_SCHEDULE_DELETE,
    iPushPullSchedule,
});
exports.IPushPullScheduleDelete = IPushPullScheduleDelete;
const IPushPullScheduleSuspend = (iPushPullSchedule) => ({
    type: exports.IPUSHPULL_SCHEDULE_SUSPEND,
    iPushPullSchedule,
});
exports.IPushPullScheduleSuspend = IPushPullScheduleSuspend;
const IPushPullScheduleUnSuspend = (iPushPullSchedule) => ({
    type: exports.IPUSHPULL_SCHEDULE_UNSUSPEND,
    iPushPullSchedule,
});
exports.IPushPullScheduleUnSuspend = IPushPullScheduleUnSuspend;
const IPushPullScheduleSuspendAll = () => ({
    type: exports.IPUSHPULL_SCHEDULE_SUSPEND,
});
exports.IPushPullScheduleSuspendAll = IPushPullScheduleSuspendAll;
const IPushPullScheduleUnSuspendAll = () => ({
    type: exports.IPUSHPULL_SCHEDULE_UNSUSPEND,
});
exports.IPushPullScheduleUnSuspendAll = IPushPullScheduleUnSuspendAll;
const initialState = {
    ReportSchedules: GeneralConstants_1.EMPTY_ARRAY,
    Reminders: GeneralConstants_1.EMPTY_ARRAY,
    IPushPullSchedules: GeneralConstants_1.EMPTY_ARRAY,
    OpenFinSchedules: GeneralConstants_1.EMPTY_ARRAY,
};
const ScheduleReducer = (state = initialState, action) => {
    switch (action.type) {
        case exports.OPENFIN_SCHEDULE_ADD: {
            const actionSchedule = action.openFinSchedule;
            AdaptableHelper_1.default.addAdaptableObjectPrimitives(actionSchedule);
            const OpenFinSchedules = [].concat(state.OpenFinSchedules);
            OpenFinSchedules.push(actionSchedule);
            return { ...state, OpenFinSchedules: OpenFinSchedules };
        }
        case exports.OPENFIN_SCHEDULE_EDIT: {
            const actionSchedule = action.openFinSchedule;
            return {
                ...state,
                OpenFinSchedules: state.OpenFinSchedules.map((abObject) => abObject.Uuid === actionSchedule.Uuid ? actionSchedule : abObject),
            };
        }
        case exports.OPENFIN_SCHEDULE_DELETE: {
            const actionSchedule = action.openFinSchedule;
            return {
                ...state,
                OpenFinSchedules: state.OpenFinSchedules.filter((abObject) => abObject.Uuid !== actionSchedule.Uuid),
            };
        }
        case exports.OPENFIN_SCHEDULE_SUSPEND: {
            return {
                ...state,
                OpenFinSchedules: (0, utils_1.changeIsSuspendInList)(action.openFinSchedule, state.OpenFinSchedules, true),
            };
        }
        case exports.OPENFIN_SCHEDULE_UNSUSPEND: {
            return {
                ...state,
                OpenFinSchedules: (0, utils_1.changeIsSuspendInList)(action.openFinSchedule, state.OpenFinSchedules, false),
            };
        }
        case exports.OPENFIN_SCHEDULE_SUSPEND_ALL: {
            return {
                ...state,
                OpenFinSchedules: (0, utils_1.suspendAllInList)(state.OpenFinSchedules),
            };
        }
        case exports.OPENFIN_SCHEDULE_UNSUSPEND_ALL: {
            return {
                ...state,
                OpenFinSchedules: (0, utils_1.unsuspendAllInList)(state.OpenFinSchedules),
            };
        }
        case exports.REPORT_SCHEDULE_ADD: {
            const actionSchedule = action.reportSchedule;
            AdaptableHelper_1.default.addAdaptableObjectPrimitives(actionSchedule);
            const reportSchedules = [].concat(state.ReportSchedules);
            reportSchedules.push(actionSchedule);
            return { ...state, ReportSchedules: reportSchedules };
        }
        case exports.REPORT_SCHEDULE_EDIT: {
            const actionSchedule = action.reportSchedule;
            return {
                ...state,
                ReportSchedules: state.ReportSchedules.map((abObject) => abObject.Uuid === actionSchedule.Uuid ? actionSchedule : abObject),
            };
        }
        case exports.REPORT_SCHEDULE_DELETE: {
            const actionSchedule = action.reportSchedule;
            return {
                ...state,
                ReportSchedules: state.ReportSchedules.filter((abObject) => abObject.Uuid !== actionSchedule.Uuid),
            };
        }
        case exports.REPORT_SCHEDULE_SUSPEND: {
            return {
                ...state,
                ReportSchedules: (0, utils_1.changeIsSuspendInList)(action.reportSchedule, state.ReportSchedules, true),
            };
        }
        case exports.REPORT_SCHEDULE_UNSUSPEND: {
            return {
                ...state,
                ReportSchedules: (0, utils_1.changeIsSuspendInList)(action.reportSchedule, state.ReportSchedules, false),
            };
        }
        case exports.REPORT_SCHEDULE_SUSPEND_ALL: {
            return {
                ...state,
                ReportSchedules: (0, utils_1.suspendAllInList)(state.ReportSchedules),
            };
        }
        case exports.REPORT_SCHEDULE_UNSUSPEND_ALL: {
            return {
                ...state,
                ReportSchedules: (0, utils_1.unsuspendAllInList)(state.ReportSchedules),
            };
        }
        case exports.REMINDER_SCHEDULE_ADD: {
            const actionSchedule = action.reminderSchedule;
            AdaptableHelper_1.default.addAdaptableObjectPrimitives(actionSchedule);
            const reminderSchedules = [].concat(state.Reminders);
            reminderSchedules.push(actionSchedule);
            return { ...state, Reminders: reminderSchedules };
        }
        case exports.REMINDER_SCHEDULE_EDIT: {
            const actionSchedule = action.reminderSchedule;
            return {
                ...state,
                Reminders: state.Reminders.map((abObject) => abObject.Uuid === actionSchedule.Uuid ? actionSchedule : abObject),
            };
        }
        case exports.REMINDER_SCHEDULE_DELETE: {
            const actionSchedule = action.reminderSchedule;
            return {
                ...state,
                Reminders: state.Reminders.filter((abObject) => abObject.Uuid !== actionSchedule.Uuid),
            };
        }
        case exports.REMINDER_SCHEDULE_SUSPEND: {
            return {
                ...state,
                Reminders: (0, utils_1.changeIsSuspendInList)(action.reminderSchedule, state.Reminders, true),
            };
        }
        case exports.REMINDER_SCHEDULE_UNSUSPEND: {
            return {
                ...state,
                Reminders: (0, utils_1.changeIsSuspendInList)(action.reminderSchedule, state.Reminders, false),
            };
        }
        case exports.REMINDER_SCHEDULE_SUSPEND_ALL: {
            return {
                ...state,
                Reminders: (0, utils_1.suspendAllInList)(state.Reminders),
            };
        }
        case exports.REMINDER_SCHEDULE_UNSUSPEND_ALL: {
            return {
                ...state,
                Reminders: (0, utils_1.unsuspendAllInList)(state.Reminders),
            };
        }
        case exports.IPUSHPULL_SCHEDULE_ADD: {
            const actionSchedule = action
                .iPushPullSchedule;
            AdaptableHelper_1.default.addAdaptableObjectPrimitives(actionSchedule);
            const iPushPullSchedules = state.IPushPullSchedules ? [...state.IPushPullSchedules] : [];
            iPushPullSchedules.push(actionSchedule);
            return { ...state, IPushPullSchedules: iPushPullSchedules };
        }
        case exports.IPUSHPULL_SCHEDULE_EDIT: {
            const actionSchedule = action
                .iPushPullSchedule;
            return {
                ...state,
                IPushPullSchedules: (state.IPushPullSchedules || []).map((abObject) => abObject.Uuid === actionSchedule.Uuid ? actionSchedule : abObject),
            };
        }
        case exports.IPUSHPULL_SCHEDULE_DELETE: {
            const actionSchedule = action
                .iPushPullSchedule;
            return {
                ...state,
                IPushPullSchedules: (state.IPushPullSchedules || []).filter((abObject) => abObject.Uuid !== actionSchedule.Uuid),
            };
        }
        case exports.IPUSHPULL_SCHEDULE_SUSPEND: {
            return {
                ...state,
                IPushPullSchedules: (0, utils_1.changeIsSuspendInList)(action.iPushPullSchedule, state.IPushPullSchedules, true),
            };
        }
        case exports.IPUSHPULL_SCHEDULE_UNSUSPEND: {
            return {
                ...state,
                IPushPullSchedules: (0, utils_1.changeIsSuspendInList)(action.iPushPullSchedule, state.IPushPullSchedules, false),
            };
        }
        case exports.IPUSHPULL_SCHEDULE_SUSPEND_ALL: {
            return {
                ...state,
                IPushPullSchedules: (0, utils_1.suspendAllInList)(state.IPushPullSchedules),
            };
        }
        case exports.IPUSHPULL_SCHEDULE_UNSUSPEND_ALL: {
            return {
                ...state,
                IPushPullSchedules: (0, utils_1.unsuspendAllInList)(state.IPushPullSchedules),
            };
        }
        default:
            return state;
    }
};
exports.ScheduleReducer = ScheduleReducer;
