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 { AbstractCommand } from '../AbstractCommand';
import { LoggerCompat } from '../../compat/LoggerCompat';
/**
 * A command used to add a new definition in a document.  Source for the new
 * definition must be provided.  This source will be converted to an OAS
 * definition object and then added to the data model.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var AddSchemaDefinitionCommand = /** @class */ (function (_super) {
    __extends(AddSchemaDefinitionCommand, _super);
    function AddSchemaDefinitionCommand(definitionName, obj) {
        var _this = this;
        if (((typeof definitionName === 'string') || definitionName === null) && ((obj != null) || obj === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._defExisted === undefined)
                _this._defExisted = false;
            if (_this._newDefinitionName === undefined)
                _this._newDefinitionName = null;
            if (_this._newDefinitionObj === undefined)
                _this._newDefinitionObj = null;
            if (_this._defExisted === undefined)
                _this._defExisted = false;
            if (_this._newDefinitionName === undefined)
                _this._newDefinitionName = null;
            if (_this._newDefinitionObj === undefined)
                _this._newDefinitionObj = null;
            (function () {
                _this._newDefinitionName = definitionName;
                _this._newDefinitionObj = obj;
            })();
        }
        else if (((typeof definitionName === 'string') || definitionName === null) && obj === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._defExisted === undefined)
                _this._defExisted = false;
            if (_this._newDefinitionName === undefined)
                _this._newDefinitionName = null;
            if (_this._newDefinitionObj === undefined)
                _this._newDefinitionObj = null;
            if (_this._defExisted === undefined)
                _this._defExisted = false;
            if (_this._newDefinitionName === undefined)
                _this._newDefinitionName = null;
            if (_this._newDefinitionObj === undefined)
                _this._newDefinitionObj = null;
            (function () {
                _this._newDefinitionName = definitionName;
            })();
        }
        else if (definitionName === undefined && obj === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._defExisted === undefined)
                _this._defExisted = false;
            if (_this._newDefinitionName === undefined)
                _this._newDefinitionName = null;
            if (_this._newDefinitionObj === undefined)
                _this._newDefinitionObj = null;
            if (_this._defExisted === undefined)
                _this._defExisted = false;
            if (_this._newDefinitionName === undefined)
                _this._newDefinitionName = null;
            if (_this._newDefinitionObj === undefined)
                _this._newDefinitionObj = null;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    AddSchemaDefinitionCommand.prototype.execute = function (document) {
        LoggerCompat.info("[AddSchemaDefinitionCommand] Executing.");
        var doc = document;
        if (this.defExists(doc)) {
            LoggerCompat.info("[AddSchemaDefinitionCommand] Definition with name %s already exists.", this._newDefinitionName);
            this._defExisted = true;
            return;
        }
        this.prepareDocumentForDef(doc);
        var definition = this.createSchemaDefinition(doc);
        this.addDefinition(doc, definition);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    AddSchemaDefinitionCommand.prototype.undo = function (document) {
        LoggerCompat.info("[AddSchemaDefinitionCommand] Reverting.");
        if (this._defExisted) {
            return;
        }
        var doc = document;
        this.removeDefinition(doc);
    };
    return AddSchemaDefinitionCommand;
}(AbstractCommand));
export { AddSchemaDefinitionCommand };
AddSchemaDefinitionCommand["__class"] = "io.apicurio.datamodels.cmd.commands.AddSchemaDefinitionCommand";
AddSchemaDefinitionCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=AddSchemaDefinitionCommand.js.map