"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.negateGroupPredicates = negateGroupPredicates;
const expandPredicates_1 = require("./_internal/expandPredicates");
/**
 * Helper function that locates group predicates and "negates" them
 * so we get a query that is `not in groups ...` vs `in groups ...`
 * @param query
 * @returns
 */
function negateGroupPredicates(query) {
    // if nothing is passed in just return undefined
    if (!query) {
        return undefined;
    }
    const expanded = (0, expandPredicates_1.expandPredicates)(query);
    // negate the group predicate on the query
    // we opted to be surgical about this vs attempting a `negateQuery(query)` function
    expanded.filters.forEach((f) => {
        f.predicates.forEach((p) => {
            if (p.group) {
                p.group.not = [...(p.group.any || []), ...(p.group.all || [])];
                p.group.any = [];
                p.group.all = [];
            }
        });
    });
    return expanded;
}
//# sourceMappingURL=negateGroupPredicates.js.map