"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAdaptableRuleValid = void 0;
const isAdaptableRuleValid = (abObject, api, context) => {
    if (abObject?.Rule?.Predicates?.length) {
        if (!api.predicateApi.isEveryPredicateValid(abObject?.Rule?.Predicates)) {
            return `The predicate${abObject?.Rule?.Predicates?.length === 1 ? ' is' : 's are'} not valid.`;
        }
    }
    if (abObject?.Rule?.BooleanExpression) {
        if (!api.expressionApi.isValidBooleanExpression(abObject?.Rule?.BooleanExpression, context.moduleInfo.ModuleName)) {
            return 'The Boolean expression is not valid.';
        }
    }
    if (abObject?.Rule?.ObservableExpression) {
        if (!api.expressionApi.isValidObservableExpression(abObject?.Rule?.ObservableExpression, context.moduleInfo.ModuleName)) {
            return 'The Observable expression is not valid.';
        }
    }
    if (abObject?.Rule?.AggregatedBooleanExpression) {
        if (!api.expressionApi.isValidAggregatedBooleanExpression(abObject?.Rule?.AggregatedBooleanExpression, context.moduleInfo.ModuleName)) {
            return 'The Aggregated Boolean expression is not valid.';
        }
    }
    if (abObject?.Rule?.Predicates?.length) {
        const isAPredicateWithInvalidColumnId = abObject?.Rule?.Predicates?.some((predicate) => predicate.ColumnId !== undefined && predicate.ColumnId === '');
        if (isAPredicateWithInvalidColumnId) {
            return 'Predicates with a custom scope require a valid column.';
        }
    }
    return true;
};
exports.isAdaptableRuleValid = isAdaptableRuleValid;
