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 { OasOperation } from '../../openapi/models/OasOperation';
/**
 * A command used to create a new request body (parameter of an operation).
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var NewRequestBodyCommand = /** @class */ (function (_super) {
    __extends(NewRequestBodyCommand, _super);
    function NewRequestBodyCommand(operation) {
        var _this = this;
        if (((operation != null && operation instanceof OasOperation) || operation === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._operationPath === undefined)
                _this._operationPath = null;
            if (_this._created === undefined)
                _this._created = false;
            if (_this._operationPath === undefined)
                _this._operationPath = null;
            if (_this._created === undefined)
                _this._created = false;
            (function () {
                _this._operationPath = Library.createNodePath(operation);
            })();
        }
        else if (operation === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._operationPath === undefined)
                _this._operationPath = null;
            if (_this._created === undefined)
                _this._created = false;
            if (_this._operationPath === undefined)
                _this._operationPath = null;
            if (_this._created === undefined)
                _this._created = false;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewRequestBodyCommand.prototype.execute = function (document) {
        LoggerCompat.info("[NewRequestBodyCommand] Executing.");
        this._created = false;
        var operation = this._operationPath.resolve(document);
        if (this.isNullOrUndefined(operation)) {
            return;
        }
        if (this.hasRequestBody(operation)) {
            return;
        }
        this.doCreateRequestBody(operation);
        this._created = true;
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewRequestBodyCommand.prototype.undo = function (document) {
        LoggerCompat.info("[NewRequestBodyCommand] Reverting.");
        if (!this._created) {
            return;
        }
        var operation = this._operationPath.resolve(document);
        if (this.isNullOrUndefined(operation)) {
            return;
        }
        this.doRemoveRequestBody(operation);
    };
    return NewRequestBodyCommand;
}(AbstractCommand));
export { NewRequestBodyCommand };
NewRequestBodyCommand["__class"] = "io.apicurio.datamodels.cmd.commands.NewRequestBodyCommand";
NewRequestBodyCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewRequestBodyCommand.js.map