var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* Generated from Java with JSweet 2.3.7 - http://www.jsweet.org */
import { Library } from '../../Library';
import { AbstractCommand } from '../AbstractCommand';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { NodeCompat } from '../../compat/NodeCompat';
import { Node } from '../../core/models/Node';
/**
 * A command used to delete a child node.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteNodeCommand = /** @class */ (function (_super) {
    __extends(DeleteNodeCommand, _super);
    function DeleteNodeCommand(property, from) {
        var _this = this;
        if (((typeof property === 'string') || property === null) && ((from != null && from instanceof Node) || from === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._property === undefined)
                _this._property = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldValue === undefined)
                _this._oldValue = null;
            if (_this._property === undefined)
                _this._property = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldValue === undefined)
                _this._oldValue = null;
            (function () {
                _this._property = property;
                _this._parentPath = Library.createNodePath(from);
            })();
        }
        else if (property === undefined && from === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._property === undefined)
                _this._property = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldValue === undefined)
                _this._oldValue = null;
            if (_this._property === undefined)
                _this._property = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldValue === undefined)
                _this._oldValue = null;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteNodeCommand.prototype.execute = function (document) {
        LoggerCompat.info("[" + this.type() + "] Executing.");
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        var propertyNode = NodeCompat.getProperty(parent, this._property);
        if (this.isNullOrUndefined(propertyNode)) {
            this._oldValue = null;
            return;
        }
        else {
            this._oldValue = Library.writeNode(propertyNode);
        }
        NodeCompat.setProperty(parent, this._property, null);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteNodeCommand.prototype.undo = function (document) {
        LoggerCompat.info("[" + this.type() + "] Reverting.");
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent) || this.isNullOrUndefined(this._oldValue)) {
            return;
        }
        var restoredNode = this.readNode(document, this._oldValue);
        restoredNode._parent = parent;
        restoredNode._ownerDocument = parent.ownerDocument();
        NodeCompat.setProperty(parent, this._property, restoredNode);
    };
    return DeleteNodeCommand;
}(AbstractCommand));
export { DeleteNodeCommand };
DeleteNodeCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteNodeCommand";
DeleteNodeCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteNodeCommand.js.map