"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAlertTypeText = exports.getAlertType = exports.AlertType = void 0;
var AlertType;
(function (AlertType) {
    AlertType["DataChange"] = "DataChange";
    AlertType["Validation"] = "Validation";
    AlertType["RowChange"] = "RowChange";
    AlertType["Aggregation"] = "Aggregation";
    AlertType["Observable"] = "Observable";
})(AlertType = exports.AlertType || (exports.AlertType = {}));
/**
 * Based on alert shape the type is derived.
 * In the future the alert will get a type property.
 *
 * @param alert
 */
const getAlertType = (alert) => {
    var _a, _b;
    if (alert.Rule.ObservableExpression) {
        return AlertType.Observable;
    }
    if (alert.Rule.AggregatedBooleanExpression) {
        return AlertType.Aggregation;
    }
    if (alert.Rule.BooleanExpression) {
        if ((_a = alert.AlertProperties) === null || _a === void 0 ? void 0 : _a.PreventEdit) {
            return AlertType.Validation;
        }
        return AlertType.DataChange;
    }
    const predicates = alert.Rule.Predicates;
    if (predicates) {
        if (predicates.some((predicate) => ['AddedRow', 'RemovedRow'].includes(predicate.PredicateId))) {
            return AlertType.RowChange;
        }
        else {
            return ((_b = alert.AlertProperties) === null || _b === void 0 ? void 0 : _b.PreventEdit) ? AlertType.Validation : AlertType.DataChange;
        }
    }
    // the object is not a valid alert
    return null;
};
exports.getAlertType = getAlertType;
const getAlertTypeText = (alertType) => {
    let text = '';
    switch (alertType) {
        case AlertType.DataChange:
            text = 'Data Change';
            break;
        case AlertType.Validation:
            text = 'Data Validation';
            break;
        case AlertType.RowChange:
            text = 'Row Change';
            break;
        case AlertType.Aggregation:
            text = 'Aggregation';
            break;
        case AlertType.Observable:
            text = 'Observable';
            break;
    }
    return text;
};
exports.getAlertTypeText = getAlertTypeText;
