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';
import { OasParameter } from '../../openapi/models/OasParameter';
/**
 * A command used to delete a single parameter from an operation.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteParameterCommand = /** @class */ (function (_super) {
    __extends(DeleteParameterCommand, _super);
    function DeleteParameterCommand(parameter) {
        var _this = this;
        if (((parameter != null && parameter instanceof OasParameter) || parameter === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldParameter === undefined)
                _this._oldParameter = null;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldParameter === undefined)
                _this._oldParameter = null;
            (function () {
                _this._parameterPath = Library.createNodePath(parameter);
                _this._parentPath = Library.createNodePath(parameter.parent());
            })();
        }
        else if (parameter === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldParameter === undefined)
                _this._oldParameter = null;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldParameter === undefined)
                _this._oldParameter = 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
     */
    DeleteParameterCommand.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteParameterCommand] Executing.");
        this._oldParameter = null;
        var param = this._parameterPath.resolve(document);
        if (this.isNullOrUndefined(param)) {
            return;
        }
        var parent = param.parent();
        var parameters = parent.getParameters();
        var idx = parameters.indexOf(param);
        if (idx === -1) {
            return;
        }
        /* remove */ parameters.splice(idx, 1)[0];
        this._oldParameter = Library.writeNode(param);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteParameterCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteParameterCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldParameter)) {
            return;
        }
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        var parameters = parent.getParameters();
        if (this.isNullOrUndefined(parameters)) {
            parameters = ([]);
            NodeCompat.setProperty(parent, Constants.PROP_PARAMETERS, parameters);
        }
        var param = parent.createParameter();
        Library.readNode(this._oldParameter, param);
        parent.addParameter(param);
    };
    return DeleteParameterCommand;
}(AbstractCommand));
export { DeleteParameterCommand };
DeleteParameterCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteParameterCommand";
DeleteParameterCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteParameterCommand.js.map