"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidAlertRules = void 0;
const Utilities_1 = require("../../Components/EntityRulesEditor/Utilities");
const isValidAlertRules = (alert, api, context) => {
    if (!alert.Rule.Predicates?.length &&
        !alert.Rule.BooleanExpression &&
        !alert.Rule.ObservableExpression &&
        !alert.Rule.AggregatedBooleanExpression) {
        return 'A rule is required for the Alert.';
    }
    const isRuleValid = (0, Utilities_1.isAdaptableRuleValid)(alert, api, context);
    if (typeof isRuleValid === 'string') {
        return isRuleValid;
    }
    // boolean expressions may also be saved as named queries
    if (context.namedQuery != false) {
        const isValidName = api.namedQueryApi.isValidNamedQuery(context.namedQuery);
        if (!isValidName.valid) {
            return isValidName.message;
        }
    }
    return true;
};
exports.isValidAlertRules = isValidAlertRules;
