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 { SimplifiedParameterType } from '../models/SimplifiedParameterType';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { Parameter } from '../../core/models/common/Parameter';
/**
 * A command used to modify the type of a parameter of an operation.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var ChangeParameterTypeCommand = /** @class */ (function (_super) {
    __extends(ChangeParameterTypeCommand, _super);
    function ChangeParameterTypeCommand(parameter, newType) {
        var _this = this;
        if (((parameter != null && parameter instanceof Parameter) || parameter === null) && ((newType != null && newType instanceof SimplifiedParameterType) || newType === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._paramPath === undefined)
                _this._paramPath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldParameter === undefined)
                _this._oldParameter = null;
            if (_this._paramPath === undefined)
                _this._paramPath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldParameter === undefined)
                _this._oldParameter = null;
            (function () {
                _this._paramPath = Library.createNodePath(parameter);
                _this._newType = newType;
            })();
        }
        else if (parameter === undefined && newType === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._paramPath === undefined)
                _this._paramPath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldParameter === undefined)
                _this._oldParameter = null;
            if (_this._paramPath === undefined)
                _this._paramPath = null;
            if (_this._newType === undefined)
                _this._newType = 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
     */
    ChangeParameterTypeCommand.prototype.execute = function (document) {
        LoggerCompat.info("[ChangeParameterTypeCommand] Executing.");
        var param = this._paramPath.resolve(document);
        if (this.isNullOrUndefined(param)) {
            return;
        }
        this._oldParameter = Library.writeNode(param);
        this.doChangeParameter(document, param);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    ChangeParameterTypeCommand.prototype.undo = function (document) {
        LoggerCompat.info("[ChangeParameterTypeCommand] Reverting.");
        var param = this._paramPath.resolve(document);
        if (this.isNullOrUndefined(param)) {
            return;
        }
        var parent = param.parent();
        var oldParam = parent.createParameter();
        Library.readNode(this._oldParameter, oldParam);
        this.doRestoreParameter(param, oldParam);
    };
    return ChangeParameterTypeCommand;
}(AbstractCommand));
export { ChangeParameterTypeCommand };
ChangeParameterTypeCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ChangeParameterTypeCommand";
ChangeParameterTypeCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ChangeParameterTypeCommand.js.map