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 { Constants } from '../../core/Constants';
/**
 * A command used to delete all servers from a document.
 *
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteAllServersCommand = /** @class */ (function (_super) {
    __extends(DeleteAllServersCommand, _super);
    function DeleteAllServersCommand(parent) {
        var _this = this;
        if (((parent != null && (parent["__interfaces"] != null && parent["__interfaces"].indexOf("io.apicurio.datamodels.core.models.common.IServerParent") >= 0 || parent.constructor != null && parent.constructor["__interfaces"] != null && parent.constructor["__interfaces"].indexOf("io.apicurio.datamodels.core.models.common.IServerParent") >= 0)) || parent === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldServers === undefined)
                _this._oldServers = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldServers === undefined)
                _this._oldServers = null;
            (function () {
                _this._parentPath = Library.createNodePath(parent);
            })();
        }
        else if (parent === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldServers === undefined)
                _this._oldServers = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldServers === undefined)
                _this._oldServers = 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
     */
    DeleteAllServersCommand.prototype.execute = function (document) {
        var _this = this;
        LoggerCompat.info("[DeleteAllServersCommand] Executing.");
        this._oldServers = ([]);
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        var servers = parent.getServers();
        if (!this.isNullOrUndefined(servers)) {
            servers.forEach(function (server) {
                /* add */ (_this._oldServers.push(Library.writeNode(server)) > 0);
            });
        }
        NodeCompat.setProperty(parent, Constants.PROP_SERVERS, ([]));
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteAllServersCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteAllServersCommand] Reverting.");
        if ( /* size */this._oldServers.length === 0) {
            return;
        }
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        var servers = parent.getServers();
        if (this.isNullOrUndefined(servers)) {
            servers = ([]);
            NodeCompat.setProperty(parent, Constants.PROP_SERVERS, servers);
        }
        for (var index202 = 0; index202 < this._oldServers.length; index202++) {
            var oldServer = this._oldServers[index202];
            {
                var server = parent.createServer();
                Library.readNode(oldServer, server);
                /* add */ (servers.push(server) > 0);
            }
        }
    };
    return DeleteAllServersCommand;
}(AbstractCommand));
export { DeleteAllServersCommand };
DeleteAllServersCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteAllServersCommand";
DeleteAllServersCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteAllServersCommand.js.map