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