"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpOr = void 0;
const AbstractSecondOrderPredicateOp_1 = require("./AbstractSecondOrderPredicateOp");
const constants_1 = require("../constants");
const json_pointer_1 = require("@jsonjoy.com/json-pointer");
/**
 * @category JSON Predicate
 */
class OpOr extends AbstractSecondOrderPredicateOp_1.AbstractSecondOrderPredicateOp {
    constructor(path, ops) {
        super(path, ops);
        this.ops = ops;
    }
    op() {
        return 'or';
    }
    code() {
        return constants_1.OPCODE.or;
    }
    test(doc) {
        for (const op of this.ops)
            if (op.test(doc))
                return true;
        return false;
    }
    toJson(parent) {
        const op = {
            op: 'or',
            path: (0, json_pointer_1.formatJsonPointer)(parent ? this.path.slice(parent.path.length) : this.path),
            apply: this.ops.map((op) => op.toJson(this)),
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'or' : constants_1.OPCODE.or;
        return [
            opcode,
            parent ? this.path.slice(parent.path.length) : this.path,
            this.ops.map((op) => op.toCompact(this, verbose)),
        ];
    }
}
exports.OpOr = OpOr;
//# sourceMappingURL=OpOr.js.map