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';
/**
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var ChangeContactCommand = /** @class */ (function (_super) {
    __extends(ChangeContactCommand, _super);
    function ChangeContactCommand(name, email, url) {
        var _this = this;
        if (((typeof name === 'string') || name === null) && ((typeof email === 'string') || email === null) && ((typeof url === 'string') || url === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._newName === undefined)
                _this._newName = null;
            if (_this._newEmail === undefined)
                _this._newEmail = null;
            if (_this._newUrl === undefined)
                _this._newUrl = null;
            if (_this._oldContact === undefined)
                _this._oldContact = null;
            if (_this._nullInfo === undefined)
                _this._nullInfo = false;
            if (_this._newName === undefined)
                _this._newName = null;
            if (_this._newEmail === undefined)
                _this._newEmail = null;
            if (_this._newUrl === undefined)
                _this._newUrl = null;
            if (_this._oldContact === undefined)
                _this._oldContact = null;
            if (_this._nullInfo === undefined)
                _this._nullInfo = false;
            (function () {
                _this._newName = name;
                _this._newEmail = email;
                _this._newUrl = url;
            })();
        }
        else if (name === undefined && email === undefined && url === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._newName === undefined)
                _this._newName = null;
            if (_this._newEmail === undefined)
                _this._newEmail = null;
            if (_this._newUrl === undefined)
                _this._newUrl = null;
            if (_this._oldContact === undefined)
                _this._oldContact = null;
            if (_this._nullInfo === undefined)
                _this._nullInfo = false;
            if (_this._newName === undefined)
                _this._newName = null;
            if (_this._newEmail === undefined)
                _this._newEmail = null;
            if (_this._newUrl === undefined)
                _this._newUrl = null;
            if (_this._oldContact === undefined)
                _this._oldContact = 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
     */
    ChangeContactCommand.prototype.execute = function (document) {
        LoggerCompat.info("[ChangeContactCommand] Executing.");
        this._oldContact = null;
        this._nullInfo = false;
        if (this.isNullOrUndefined(document.info)) {
            this._nullInfo = true;
            document.info = document.createInfo();
            this._oldContact = null;
        }
        else {
            this._oldContact = null;
            if (ModelUtils.isDefined(document.info.contact)) {
                this._oldContact = Library.writeNode(document.info.contact);
            }
        }
        document.info.contact = document.info.createContact();
        document.info.contact.name = this._newName;
        document.info.contact.url = this._newUrl;
        document.info.contact.email = this._newEmail;
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    ChangeContactCommand.prototype.undo = function (document) {
        LoggerCompat.info("[ChangeContactCommand] Reverting.");
        if (this._nullInfo) {
            document.info = null;
        }
        else if (ModelUtils.isDefined(this._oldContact)) {
            document.info.contact = document.info.createContact();
            Library.readNode(this._oldContact, document.info.contact);
        }
        else {
            document.info.contact = null;
        }
    };
    return ChangeContactCommand;
}(AbstractCommand));
export { ChangeContactCommand };
ChangeContactCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ChangeContactCommand";
ChangeContactCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ChangeContactCommand.js.map