import { find, formatJsonPointer } from '@jsonjoy.com/json-pointer';
import { AbstractPredicateOp } from './AbstractPredicateOp';
import { OPCODE } from '../constants';
import { deepEqual } from '@jsonjoy.com/util/lib/json-equal/deepEqual';
/**
 * @category JSON Predicate
 */
export class OpIn extends AbstractPredicateOp {
    value;
    constructor(path, value) {
        super(path);
        this.value = value;
    }
    op() {
        return 'in';
    }
    code() {
        return OPCODE.in;
    }
    test(doc) {
        const { val } = find(doc, this.path);
        for (const x of this.value)
            if (deepEqual(val, x))
                return true;
        return false;
    }
    toJson(parent) {
        const op = {
            op: 'in',
            path: formatJsonPointer(parent ? this.path.slice(parent.path.length) : this.path),
            value: this.value,
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'in' : OPCODE.in;
        return [opcode, parent ? this.path.slice(parent.path.length) : this.path, this.value];
    }
}
//# sourceMappingURL=OpIn.js.map