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 { ModelUtils } from '../util/ModelUtils';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { NodeCompat } from '../../compat/NodeCompat';
import { Node } from '../../core/models/Node';
/**
 * A command used to modify the simple property of a node.  Should not be used
 * to modify complex (object) properties, only simple property types like
 * string, boolean, number, etc.
 *
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var ChangePropertyCommand = /** @class */ (function (_super) {
    __extends(ChangePropertyCommand, _super);
    function ChangePropertyCommand(node, property, newValue) {
        var _this = this;
        if (((node != null && node instanceof Node) || node === null) && ((typeof property === 'string') || property === null) && ((newValue != null) || newValue === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._nodePath === undefined)
                _this._nodePath = null;
            if (_this._property === undefined)
                _this._property = null;
            if (_this._newValue === undefined)
                _this._newValue = null;
            if (_this._oldValue === undefined)
                _this._oldValue = null;
            if (_this._nodePath === undefined)
                _this._nodePath = null;
            if (_this._property === undefined)
                _this._property = null;
            if (_this._newValue === undefined)
                _this._newValue = null;
            if (_this._oldValue === undefined)
                _this._oldValue = null;
            (function () {
                if (ModelUtils.isDefined(node)) {
                    _this._nodePath = Library.createNodePath(node);
                }
                _this._property = property;
                _this._newValue = newValue;
            })();
        }
        else if (node === undefined && property === undefined && newValue === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._nodePath === undefined)
                _this._nodePath = null;
            if (_this._property === undefined)
                _this._property = null;
            if (_this._newValue === undefined)
                _this._newValue = null;
            if (_this._oldValue === undefined)
                _this._oldValue = null;
            if (_this._nodePath === undefined)
                _this._nodePath = null;
            if (_this._property === undefined)
                _this._property = null;
            if (_this._newValue === undefined)
                _this._newValue = 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
     */
    ChangePropertyCommand.prototype.execute = function (document) {
        LoggerCompat.info("[ChangePropertyCommand] Executing.");
        var node = this._nodePath.resolve(document);
        if (this.isNullOrUndefined(node)) {
            return;
        }
        this._oldValue = NodeCompat.getProperty(node, this._property);
        NodeCompat.setProperty(node, this._property, this._newValue);
    };
    /**
     *
     * @param {Document} document
     */
    ChangePropertyCommand.prototype.undo = function (document) {
        LoggerCompat.info("[ChangePropertyCommand] Reverting.");
        var node = this._nodePath.resolve(document);
        if (this.isNullOrUndefined(node)) {
            return;
        }
        NodeCompat.setProperty(node, this._property, this._oldValue);
        this._oldValue = null;
    };
    return ChangePropertyCommand;
}(AbstractCommand));
export { ChangePropertyCommand };
ChangePropertyCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ChangePropertyCommand";
ChangePropertyCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ChangePropertyCommand.js.map