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 { LoggerCompat } from '../../compat/LoggerCompat';
import { NewResponseDefinitionCommand } from './NewResponseDefinitionCommand';
/**
 * @author eric.wittmann@gmail.com
 * @extends NewResponseDefinitionCommand
 * @class
 */
var NewResponseDefinitionCommand_30 = /** @class */ (function (_super) {
    __extends(NewResponseDefinitionCommand_30, _super);
    function NewResponseDefinitionCommand_30(definitionName, description) {
        var _this = this;
        if (((typeof definitionName === 'string') || definitionName === null) && ((typeof description === 'string') || description === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._nullComponents === undefined)
                _this._nullComponents = false;
            if (_this._nullComponents === undefined)
                _this._nullComponents = false;
            (function () {
                _this._newDefinitionName = definitionName;
                _this._newDefinitionDescription = description;
            })();
        }
        else if (definitionName === undefined && description === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._nullComponents === undefined)
                _this._nullComponents = false;
            if (_this._nullComponents === undefined)
                _this._nullComponents = 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
     */
    NewResponseDefinitionCommand_30.prototype.execute = function (document) {
        LoggerCompat.info("[NewResponseDefinitionCommand] Executing.");
        var doc30 = document;
        if (this.isNullOrUndefined(doc30.components)) {
            doc30.components = doc30.createComponents();
            this._nullComponents = true;
        }
        this._nullComponents = false;
        if (this.isNullOrUndefined(doc30.components.getResponseDefinition(this._newDefinitionName))) {
            var definition = doc30.components.createResponseDefinition(this._newDefinitionName);
            if (ModelUtils.isDefined(this._newDefinitionDescription)) {
                definition.description = this._newDefinitionDescription;
            }
            doc30.components.addResponseDefinition(this._newDefinitionName, definition);
            this._defExisted = false;
        }
        else {
            this._defExisted = true;
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewResponseDefinitionCommand_30.prototype.undo = function (document) {
        LoggerCompat.info("[NewResponseDefinitionCommand] Reverting.");
        var doc30 = document;
        if (this._nullComponents) {
            doc30.components = null;
        }
        if (this._defExisted) {
            return;
        }
        doc30.components.removeResponseDefinition(this._newDefinitionName);
    };
    return NewResponseDefinitionCommand_30;
}(NewResponseDefinitionCommand));
export { NewResponseDefinitionCommand_30 };
NewResponseDefinitionCommand_30["__class"] = "io.apicurio.datamodels.cmd.commands.NewResponseDefinitionCommand_30";
NewResponseDefinitionCommand_30["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewResponseDefinitionCommand_30.js.map