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';
/**
 * A command used to delete all parameters from an operation.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteAllParametersCommand = /** @class */ (function (_super) {
    __extends(DeleteAllParametersCommand, _super);
    function DeleteAllParametersCommand(parent, type) {
        var _this = this;
        if (((parent != null && (parent["__interfaces"] != null && parent["__interfaces"].indexOf("io.apicurio.datamodels.openapi.models.IOasParameterParent") >= 0 || parent.constructor != null && parent.constructor["__interfaces"] != null && parent.constructor["__interfaces"].indexOf("io.apicurio.datamodels.openapi.models.IOasParameterParent") >= 0)) || parent === null) && ((typeof type === 'string') || type === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._paramType === undefined)
                _this._paramType = null;
            if (_this._oldParams === undefined)
                _this._oldParams = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._paramType === undefined)
                _this._paramType = null;
            if (_this._oldParams === undefined)
                _this._oldParams = null;
            (function () {
                _this._parentPath = Library.createNodePath(parent);
                _this._paramType = type;
            })();
        }
        else if (parent === undefined && type === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._paramType === undefined)
                _this._paramType = null;
            if (_this._oldParams === undefined)
                _this._oldParams = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._paramType === undefined)
                _this._paramType = null;
            if (_this._oldParams === undefined)
                _this._oldParams = 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
     */
    DeleteAllParametersCommand.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteAllParameters] Executing.");
        this._oldParams = ([]);
        var parent = this._parentPath.resolve(document);
        var parameters = parent.getParameters();
        if (this.isNullOrUndefined(parent) || this.isNullOrUndefined(parameters) || /* size */ parameters.length === 0) {
            return;
        }
        var paramsToRemove = ([]);
        for (var index204 = 0; index204 < parameters.length; index204++) {
            var param = parameters[index204];
            {
                if (NodeCompat.equals(param.in, this._paramType)) {
                    /* add */ (this._oldParams.push(Library.writeNode(param)) > 0);
                    /* add */ (paramsToRemove.push(param) > 0);
                }
            }
        }
        if ( /* size */this._oldParams.length === 0) {
            return;
        }
        paramsToRemove.forEach((function (parameters) {
            return function (paramToRemove) {
                /* remove */ (function (a) { var index = a.indexOf(paramToRemove); if (index >= 0) {
                    a.splice(index, 1);
                    return true;
                }
                else {
                    return false;
                } })(parameters);
            };
        })(parameters));
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteAllParametersCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteAllParameters] Reverting.");
        if (this.isNullOrUndefined(this._oldParams) || /* size */ this._oldParams.length === 0) {
            return;
        }
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        this._oldParams.forEach((function (parent) {
            return function (param) {
                var p = parent.createParameter();
                Library.readNode(param, p);
                parent.addParameter(p);
            };
        })(parent));
    };
    return DeleteAllParametersCommand;
}(AbstractCommand));
export { DeleteAllParametersCommand };
DeleteAllParametersCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteAllParametersCommand";
DeleteAllParametersCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteAllParametersCommand.js.map