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 { ModelUtils } from '../util/ModelUtils';
import { LoggerCompat } from '../../compat/LoggerCompat';
/**
 * A command used to modify the description of a document.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var ChangeDescriptionCommand = /** @class */ (function (_super) {
    __extends(ChangeDescriptionCommand, _super);
    function ChangeDescriptionCommand(newDescription) {
        var _this = this;
        if (((typeof newDescription === 'string') || newDescription === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._newDescription === undefined)
                _this._newDescription = null;
            if (_this._oldDescription === undefined)
                _this._oldDescription = null;
            if (_this._nullInfo === undefined)
                _this._nullInfo = false;
            if (_this._newDescription === undefined)
                _this._newDescription = null;
            if (_this._oldDescription === undefined)
                _this._oldDescription = null;
            if (_this._nullInfo === undefined)
                _this._nullInfo = false;
            (function () {
                _this._newDescription = newDescription;
            })();
        }
        else if (newDescription === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._newDescription === undefined)
                _this._newDescription = null;
            if (_this._oldDescription === undefined)
                _this._oldDescription = null;
            if (_this._nullInfo === undefined)
                _this._nullInfo = false;
            if (_this._newDescription === undefined)
                _this._newDescription = null;
            if (_this._oldDescription === undefined)
                _this._oldDescription = null;
            if (_this._nullInfo === undefined)
                _this._nullInfo = 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
     */
    ChangeDescriptionCommand.prototype.execute = function (document) {
        LoggerCompat.info("[ChangeDescriptionCommand] Executing.");
        if (ModelUtils.isNullOrUndefined(document.info)) {
            document.info = document.createInfo();
            this._nullInfo = true;
            this._oldDescription = null;
        }
        else {
            this._oldDescription = document.info.description;
        }
        document.info.description = this._newDescription;
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    ChangeDescriptionCommand.prototype.undo = function (document) {
        LoggerCompat.info("[ChangeDescriptionCommand] Reverting.");
        if (this._nullInfo) {
            document.info = null;
        }
        else {
            document.info.description = this._oldDescription;
        }
    };
    return ChangeDescriptionCommand;
}(AbstractCommand));
export { ChangeDescriptionCommand };
ChangeDescriptionCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ChangeDescriptionCommand";
ChangeDescriptionCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ChangeDescriptionCommand.js.map