import { AbstractOp } from './AbstractOp';
import { find, formatJsonPointer } from '@jsonjoy.com/json-pointer';
import { OPCODE } from '../constants';
/**
 * @category JSON Patch Extended
 */
export class OpFlip extends AbstractOp {
    op() {
        return 'flip';
    }
    code() {
        return OPCODE.flip;
    }
    apply(doc) {
        const ref = find(doc, this.path);
        if (ref.obj)
            ref.obj[ref.key] = !ref.val;
        else
            doc = !ref.val;
        return { doc, old: ref.val };
    }
    toJson(parent) {
        const op = {
            op: 'flip',
            path: formatJsonPointer(this.path),
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'flip' : OPCODE.flip;
        return [opcode, this.path];
    }
}
//# sourceMappingURL=OpFlip.js.map