"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpFlip = void 0;
const AbstractOp_1 = require("./AbstractOp");
const json_pointer_1 = require("@jsonjoy.com/json-pointer");
const constants_1 = require("../constants");
/**
 * @category JSON Patch Extended
 */
class OpFlip extends AbstractOp_1.AbstractOp {
    op() {
        return 'flip';
    }
    code() {
        return constants_1.OPCODE.flip;
    }
    apply(doc) {
        const ref = (0, json_pointer_1.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: (0, json_pointer_1.formatJsonPointer)(this.path),
        };
        return op;
    }
    toCompact(parent, verbose) {
        const opcode = verbose ? 'flip' : constants_1.OPCODE.flip;
        return [opcode, this.path];
    }
}
exports.OpFlip = OpFlip;
//# sourceMappingURL=OpFlip.js.map