import assertUnreachable from '../utils/assertUnreachable';
import { SchedulerResourceType } from './schedulerLog';
export var SchedulerJobStatus;
(function (SchedulerJobStatus) {
    SchedulerJobStatus["SCHEDULED"] = "scheduled";
    SchedulerJobStatus["STARTED"] = "started";
    SchedulerJobStatus["COMPLETED"] = "completed";
    SchedulerJobStatus["ERROR"] = "error";
})(SchedulerJobStatus || (SchedulerJobStatus = {}));
export var SchedulerFormat;
(function (SchedulerFormat) {
    SchedulerFormat["CSV"] = "csv";
    SchedulerFormat["XLSX"] = "xlsx";
    SchedulerFormat["IMAGE"] = "image";
    SchedulerFormat["GSHEETS"] = "gsheets";
    SchedulerFormat["PDF"] = "pdf";
})(SchedulerFormat || (SchedulerFormat = {}));
export var JobPriority;
(function (JobPriority) {
    JobPriority[JobPriority["HIGH"] = 0] = "HIGH";
    JobPriority[JobPriority["MEDIUM"] = 1] = "MEDIUM";
    JobPriority[JobPriority["LOW"] = 2] = "LOW";
})(JobPriority || (JobPriority = {}));
export var ThresholdOperator;
(function (ThresholdOperator) {
    ThresholdOperator["GREATER_THAN"] = "greaterThan";
    ThresholdOperator["LESS_THAN"] = "lessThan";
    ThresholdOperator["INCREASED_BY"] = "increasedBy";
    ThresholdOperator["DECREASED_BY"] = "decreasedBy";
    // HAS_CHANGED = '=',
})(ThresholdOperator || (ThresholdOperator = {}));
export var NotificationFrequency;
(function (NotificationFrequency) {
    NotificationFrequency["ALWAYS"] = "always";
    NotificationFrequency["ONCE"] = "once";
    // DAILY = 'daily',
})(NotificationFrequency || (NotificationFrequency = {}));
export const operatorActionValue = (operator, value, highlight = '*') => {
    switch (operator) {
        case ThresholdOperator.GREATER_THAN:
            return `exceeded ${highlight}${value}${highlight}`;
        case ThresholdOperator.LESS_THAN:
            return `fell below ${highlight}${value}${highlight}`;
        case ThresholdOperator.INCREASED_BY:
            return `increased by ${highlight}${value}%${highlight} or more`;
        case ThresholdOperator.DECREASED_BY:
            return `decreased by ${highlight}${value}%${highlight} or less`;
        default:
            assertUnreachable(operator, `Unknown threshold operator: ${operator}`);
    }
    return '';
};
export const isDashboardScheduler = (scheduler) => 'dashboardUuid' in scheduler && !!scheduler.dashboardUuid;
export const isAppScheduler = (data) => 'appUuid' in data && !!data.appUuid;
export const isSqlChartScheduler = (scheduler) => 'savedSqlUuid' in scheduler && !!scheduler.savedSqlUuid;
export const getSchedulerTargetUuid = (target) => {
    if ('schedulerSlackTargetUuid' in target) {
        return target.schedulerSlackTargetUuid;
    }
    if ('schedulerMsTeamsTargetUuid' in target) {
        return target.schedulerMsTeamsTargetUuid;
    }
    if ('schedulerGoogleChatTargetUuid' in target) {
        return target.schedulerGoogleChatTargetUuid;
    }
    if ('schedulerEmailTargetUuid' in target) {
        return target.schedulerEmailTargetUuid;
    }
    return undefined;
};
export const isUpdateSchedulerSlackTarget = (data) => 'schedulerSlackTargetUuid' in data && !!data.schedulerSlackTargetUuid;
export const isUpdateSchedulerMsTeamsTarget = (data) => 'schedulerMsTeamsTargetUuid' in data && !!data.schedulerMsTeamsTargetUuid;
export const isUpdateSchedulerGoogleChatTarget = (data) => 'schedulerGoogleChatTargetUuid' in data &&
    !!data.schedulerGoogleChatTargetUuid;
export const isUpdateSchedulerEmailTarget = (data) => 'schedulerEmailTargetUuid' in data && !!data.schedulerEmailTargetUuid;
export const isChartScheduler = (data) => 'savedChartUuid' in data && !!data.savedChartUuid;
export const getSchedulerResourceTypeAndId = (scheduler) => {
    if (isChartScheduler(scheduler)) {
        return {
            resourceType: SchedulerResourceType.CHART,
            resourceId: scheduler.savedChartUuid,
        };
    }
    if (isSqlChartScheduler(scheduler)) {
        return {
            resourceType: SchedulerResourceType.SQL_CHART,
            resourceId: scheduler.savedSqlUuid,
        };
    }
    if (isDashboardScheduler(scheduler)) {
        return {
            resourceType: SchedulerResourceType.DASHBOARD,
            resourceId: scheduler.dashboardUuid,
        };
    }
    if (isAppScheduler(scheduler)) {
        return {
            resourceType: SchedulerResourceType.APP,
            resourceId: scheduler.appUuid,
        };
    }
    throw new Error('Unknown scheduler resource type');
};
export const isChartCreateScheduler = (data) => 'savedChartUuid' in data && !!data.savedChartUuid;
export const isDashboardCreateScheduler = (data) => 'dashboardUuid' in data && !!data.dashboardUuid;
export const isAppCreateScheduler = (data) => 'appUuid' in data && !!data.appUuid;
export const isSlackTarget = (target) => 'channel' in target;
export const isMsTeamsTarget = (target) => 'webhook' in target;
export const isGoogleChatTarget = (target) => 'googleChatWebhook' in target;
export const isEmailTarget = (target) => 'recipient' in target;
export const isCreateSchedulerSlackTarget = (target) => 'channel' in target;
export const isCreateSchedulerMsTeamsTarget = (target) => 'webhook' in target;
export const isCreateSchedulerGoogleChatTarget = (target) => 'googleChatWebhook' in target;
export const isSchedulerCsvOptions = (options) => options && 'limit' in options;
export const isSchedulerImageOptions = (options) => options && 'withPdf' in options;
export const isSchedulerGsheetsOptions = (options) => options && 'gdriveId' in options;
export const isCreateScheduler = (data) => 'targets' in data;
export const hasSchedulerUuid = (data) => 'schedulerUuid' in data;
export const getSchedulerUuid = (data) => 'schedulerUuid' in data ? data.schedulerUuid : undefined;
export var LightdashPage;
(function (LightdashPage) {
    LightdashPage["DASHBOARD"] = "dashboard";
    LightdashPage["CHART"] = "chart";
    LightdashPage["EXPLORE"] = "explore";
    LightdashPage["SQL_CHART"] = "sql_chart";
    LightdashPage["APP"] = "app";
})(LightdashPage || (LightdashPage = {}));
//# sourceMappingURL=scheduler.js.map