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 { SimplifiedParameterType } from '../models/SimplifiedParameterType';
import { ModelUtils } from '../util/ModelUtils';
import { SimplifiedTypeUtil } from '../util/SimplifiedTypeUtil';
import { NodeCompat } from '../../compat/NodeCompat';
import { Parameter } from '../../core/models/common/Parameter';
import { ChangeParameterTypeCommand } from './ChangeParameterTypeCommand';
/**
 * OAI 2.0 Impl.
 * @author eric.wittmann@gmail.com
 * @extends ChangeParameterTypeCommand
 * @class
 */
var ChangeParameterTypeCommand_20 = /** @class */ (function (_super) {
    __extends(ChangeParameterTypeCommand_20, _super);
    function ChangeParameterTypeCommand_20(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, parameter, newType) || this;
        }
        else if (parameter === undefined && newType === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.commands.ChangeParameterTypeCommand#doChangeParameter(io.apicurio.datamodels.core.models.Document, io.apicurio.datamodels.core.models.common.Parameter)
     * @param {Document} document
     * @param {Parameter} parameter
     */
    ChangeParameterTypeCommand_20.prototype.doChangeParameter = function (document, parameter) {
        var param = parameter;
        if (NodeCompat.equals(param.in, "body")) {
            param.schema = param.createSchema();
            SimplifiedTypeUtil.setSimplifiedType(param.schema, this._newType);
        }
        else {
            SimplifiedTypeUtil.setSimplifiedTypeOnParam(param, this._newType);
        }
        var required = this._newType.required;
        if (NodeCompat.equals(param.in, "path")) {
            required = true;
        }
        if (!this.isNullOrUndefined(required)) {
            param.required = required;
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.ChangeParameterTypeCommand#doRestoreParameter(io.apicurio.datamodels.core.models.common.Parameter, io.apicurio.datamodels.core.models.common.Parameter)
     * @param {Parameter} parameter
     * @param {Parameter} oldParameter
     */
    ChangeParameterTypeCommand_20.prototype.doRestoreParameter = function (parameter, oldParameter) {
        var param = parameter;
        var oldParam = oldParameter;
        if (NodeCompat.equals(param.in, "body")) {
            param.schema = oldParam.schema;
            if (ModelUtils.isDefined(param.schema)) {
                param.schema._parent = param;
                param.schema._ownerDocument = param.ownerDocument();
            }
        }
        else {
            param.type = oldParam.type;
            param.format = oldParam.format;
            param.items = oldParam.items;
            if (ModelUtils.isDefined(param.items)) {
                param.items._parent = param;
                param.items._ownerDocument = param.ownerDocument();
            }
        }
        param.required = oldParam.required;
    };
    return ChangeParameterTypeCommand_20;
}(ChangeParameterTypeCommand));
export { ChangeParameterTypeCommand_20 };
ChangeParameterTypeCommand_20["__class"] = "io.apicurio.datamodels.cmd.commands.ChangeParameterTypeCommand_20";
ChangeParameterTypeCommand_20["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ChangeParameterTypeCommand_20.js.map