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