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 { ModelUtils } from '../util/ModelUtils';
import { NodeCompat } from '../../compat/NodeCompat';
import { Constants } from '../../core/Constants';
import { OasOperation } from '../../openapi/models/OasOperation';
import { NewRequestBodyCommand } from './NewRequestBodyCommand';
/**
 * @author eric.wittmann@gmail.com
 * @extends NewRequestBodyCommand
 * @class
 */
var NewRequestBodyCommand_20 = /** @class */ (function (_super) {
    __extends(NewRequestBodyCommand_20, _super);
    function NewRequestBodyCommand_20(operation) {
        var _this = this;
        if (((operation != null && operation instanceof OasOperation) || operation === null)) {
            var __args = arguments;
            _this = _super.call(this, operation) || this;
        }
        else if (operation === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.commands.NewRequestBodyCommand#hasRequestBody(io.apicurio.datamodels.openapi.models.OasOperation)
     * @param {OasOperation} operation
     * @return {boolean}
     */
    NewRequestBodyCommand_20.prototype.hasRequestBody = function (operation) {
        return ModelUtils.isDefined(operation) && /* size */ operation.getParametersIn("body").length > 0;
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.NewRequestBodyCommand#doCreateRequestBody(io.apicurio.datamodels.openapi.models.OasOperation)
     * @param {OasOperation} operation
     */
    NewRequestBodyCommand_20.prototype.doCreateRequestBody = function (operation) {
        if (this.isNullOrUndefined(operation.parameters)) {
            operation.parameters = ([]);
        }
        var param = operation.createParameter();
        param.in = "body";
        param.name = "body";
        operation.addParameter(param);
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.NewRequestBodyCommand#doRemoveRequestBody(io.apicurio.datamodels.openapi.models.OasOperation)
     * @param {OasOperation} operation
     */
    NewRequestBodyCommand_20.prototype.doRemoveRequestBody = function (operation) {
        var parameters = operation.getParameters();
        var bodyParams = operation.getParametersIn("body");
        for (var index230 = 0; index230 < bodyParams.length; index230++) {
            var bodyParam = bodyParams[index230];
            {
                /* remove */ parameters.splice(parameters.indexOf(bodyParam), 1)[0];
            }
        }
        parameters = operation.getParameters();
        if ( /* size */parameters.length === 0) {
            NodeCompat.setProperty(operation, Constants.PROP_PARAMETERS, null);
        }
    };
    return NewRequestBodyCommand_20;
}(NewRequestBodyCommand));
export { NewRequestBodyCommand_20 };
NewRequestBodyCommand_20["__class"] = "io.apicurio.datamodels.cmd.commands.NewRequestBodyCommand_20";
NewRequestBodyCommand_20["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewRequestBodyCommand_20.js.map