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