"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpIn = void 0;
const json_pointer_1 = require("@jsonjoy.com/json-pointer");
const AbstractPredicateOp_1 = require("./AbstractPredicateOp");
const constants_1 = require("../constants");
const deepEqual_1 = require("@jsonjoy.com/util/lib/json-equal/deepEqual");
/**
 * @category JSON Predicate
 */
class OpIn extends AbstractPredicateOp_1.AbstractPredicateOp {
    constructor(path, value) {
        super(path);
        this.value = value;
    }
    op() {
        return 'in';
    }
    code() {
        return constants_1.OPCODE.in;
    }
    test(doc) {
        const { val } = (0, json_pointer_1.find)(doc, this.path);
        for (const x of this.value)
            if ((0, deepEqual_1.deepEqual)(val, x))
                return true;
        return false;
    }
    toJson(parent) {
        const op = {
            op: 'in',
            path: (0, json_pointer_1.formatJsonPointer)(parent ? this.path.slice(parent.path.length) : this.path),
            value: this.value,
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'in' : constants_1.OPCODE.in;
        return [opcode, parent ? this.path.slice(parent.path.length) : this.path, this.value];
    }
}
exports.OpIn = OpIn;
//# sourceMappingURL=OpIn.js.map