import { AbstractPredicateOp } from './AbstractPredicateOp';
import { find, formatJsonPointer } from '@jsonjoy.com/json-pointer';
import { OPCODE } from '../constants';
/**
 * @category JSON Predicate
 */
export class OpLess extends AbstractPredicateOp {
    value;
    constructor(path, value) {
        super(path);
        this.value = value;
    }
    op() {
        return 'less';
    }
    code() {
        return OPCODE.less;
    }
    test(doc) {
        const { val } = find(doc, this.path);
        if (typeof val !== 'number')
            return false;
        const test = val < this.value;
        return test;
    }
    toJson(parent) {
        const op = {
            op: 'less',
            path: formatJsonPointer(parent ? this.path.slice(parent.path.length) : this.path),
            value: this.value,
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'less' : OPCODE.less;
        return [opcode, parent ? this.path.slice(parent.path.length) : this.path, this.value];
    }
}
//# sourceMappingURL=OpLess.js.map