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_20 = /** @class */ (function (_super) {
    __extends(NewResponseDefinitionCommand_20, _super);
    function NewResponseDefinitionCommand_20(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._nullResponses === undefined)
                _this._nullResponses = false;
            if (_this._nullResponses === undefined)
                _this._nullResponses = false;
            (function () {
                _this._newDefinitionName = definitionName;
                _this._newDefinitionDescription = description;
            })();
        }
        else if (definitionName === undefined && description === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._nullResponses === undefined)
                _this._nullResponses = false;
            if (_this._nullResponses === undefined)
                _this._nullResponses = 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_20.prototype.execute = function (document) {
        LoggerCompat.info("[NewResponseDefinitionCommand] Executing.");
        var doc20 = document;
        if (this.isNullOrUndefined(doc20.responses)) {
            doc20.responses = doc20.createResponseDefinitions();
            this._nullResponses = true;
        }
        if (this.isNullOrUndefined(doc20.responses.getResponse(this._newDefinitionName))) {
            var responseDef = doc20.responses.createResponse(this._newDefinitionName);
            if (ModelUtils.isDefined(this._newDefinitionDescription)) {
                responseDef.description = this._newDefinitionDescription;
            }
            doc20.responses.addResponse(this._newDefinitionName, responseDef);
            this._defExisted = false;
        }
        else {
            this._defExisted = true;
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewResponseDefinitionCommand_20.prototype.undo = function (document) {
        LoggerCompat.info("[NewResponseDefinitionCommand] Reverting.");
        var doc20 = document;
        if (this._nullResponses) {
            doc20.responses = null;
        }
        if (this._defExisted) {
            return;
        }
        doc20.responses.removeResponse(this._newDefinitionName);
    };
    return NewResponseDefinitionCommand_20;
}(NewResponseDefinitionCommand));
export { NewResponseDefinitionCommand_20 };
NewResponseDefinitionCommand_20["__class"] = "io.apicurio.datamodels.cmd.commands.NewResponseDefinitionCommand_20";
NewResponseDefinitionCommand_20["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewResponseDefinitionCommand_20.js.map