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 { JsonCompat } from '../../compat/JsonCompat';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { NodeCompat } from '../../compat/NodeCompat';
import { OasPathItem } from '../../openapi/models/OasPathItem';
/**
 * A command used to delete all servers from a document.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteAllOperationsCommand = /** @class */ (function (_super) {
    __extends(DeleteAllOperationsCommand, _super);
    function DeleteAllOperationsCommand(parent) {
        var _this = this;
        if (((parent != null && parent instanceof OasPathItem) || parent === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldOperations === undefined)
                _this._oldOperations = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldOperations === undefined)
                _this._oldOperations = 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._oldOperations === undefined)
                _this._oldOperations = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldOperations === undefined)
                _this._oldOperations = null;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    DeleteAllOperationsCommand.ALL_METHODS_$LI$ = function () { if (DeleteAllOperationsCommand.ALL_METHODS == null)
        DeleteAllOperationsCommand.ALL_METHODS = ["get", "put", "post", "delete", "head", "patch", "options", "trace"]; return DeleteAllOperationsCommand.ALL_METHODS; };
    ;
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteAllOperationsCommand.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteAllOperationsCommand] Executing.");
        this._oldOperations = ([]);
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        for (var index213 = 0; index213 < DeleteAllOperationsCommand.ALL_METHODS_$LI$().length; index213++) {
            var method = DeleteAllOperationsCommand.ALL_METHODS_$LI$()[index213];
            {
                var oldOp = NodeCompat.getProperty(parent, method);
                if (!this.isNullOrUndefined(oldOp)) {
                    var oldOpData = JsonCompat.objectNode();
                    JsonCompat.setPropertyString(oldOpData, "_method", method);
                    JsonCompat.setProperty(oldOpData, "_operation", Library.writeNode(oldOp));
                    /* add */ (this._oldOperations.push(oldOpData) > 0);
                    NodeCompat.setProperty(parent, method, null);
                }
            }
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteAllOperationsCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteAllOperationsCommand] Reverting.");
        if (this._oldOperations == null || /* size */ this._oldOperations.length === 0) {
            return;
        }
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        for (var index214 = 0; index214 < this._oldOperations.length; index214++) {
            var oldOperationData = this._oldOperations[index214];
            {
                var method = JsonCompat.getPropertyString(oldOperationData, "_method");
                var operation = parent.createOperation(method);
                Library.readNode(JsonCompat.getProperty(oldOperationData, "_operation"), operation);
                NodeCompat.setProperty(parent, method, operation);
            }
        }
    };
    return DeleteAllOperationsCommand;
}(AbstractCommand));
export { DeleteAllOperationsCommand };
DeleteAllOperationsCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteAllOperationsCommand";
DeleteAllOperationsCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteAllOperationsCommand.js.map