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