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';
/**
 * A command used to delete a path.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeletePathCommand = /** @class */ (function (_super) {
    __extends(DeletePathCommand, _super);
    function DeletePathCommand(path) {
        var _this = this;
        if (((typeof path === 'string') || path === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._oldPath === undefined)
                _this._oldPath = null;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._oldPath === undefined)
                _this._oldPath = null;
            (function () {
                _this._path = path;
            })();
        }
        else if (path === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._oldPath === undefined)
                _this._oldPath = null;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._oldPath === undefined)
                _this._oldPath = 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
     */
    DeletePathCommand.prototype.execute = function (document) {
        LoggerCompat.info("[DeletePathCommand] Executing for path: %s", this._path);
        var odoc = document;
        this._oldPath = null;
        var paths = odoc.paths;
        if (this.isNullOrUndefined(paths)) {
            return;
        }
        this._oldPath = Library.writeNode(paths.removePathItem(this._path));
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeletePathCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeletePathCommand] Reverting.");
        var odoc = document;
        var paths = odoc.paths;
        if (this.isNullOrUndefined(paths) || this.isNullOrUndefined(this._oldPath)) {
            return;
        }
        var pathItem = paths.createPathItem(this._path);
        Library.readNode(this._oldPath, pathItem);
        paths.addPathItem(this._path, pathItem);
    };
    return DeletePathCommand;
}(AbstractCommand));
export { DeletePathCommand };
DeletePathCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeletePathCommand";
DeletePathCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeletePathCommand.js.map