import { AbstractSecondOrderPredicateOp } from './AbstractSecondOrderPredicateOp';
import { OPCODE } from '../constants';
import { formatJsonPointer } from '@jsonjoy.com/json-pointer';
/**
 * @category JSON Predicate
 */
export class OpAnd extends AbstractSecondOrderPredicateOp {
    ops;
    constructor(path, ops) {
        super(path, ops);
        this.ops = ops;
    }
    op() {
        return 'and';
    }
    code() {
        return OPCODE.and;
    }
    test(doc) {
        for (const op of this.ops)
            if (!op.test(doc))
                return false;
        return true;
    }
    toJson(parent) {
        const op = {
            op: 'and',
            path: 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 ? 'and' : OPCODE.and;
        return [
            opcode,
            parent ? this.path.slice(parent.path.length) : this.path,
            this.ops.map((op) => op.toCompact(this, verbose)),
        ];
    }
}
//# sourceMappingURL=OpAnd.js.map