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 { LoggerCompat } from '../../compat/LoggerCompat';
import { SecurityScheme } from '../../core/models/common/SecurityScheme';
/**
 * A command used to modify a security scheme.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var ChangeSecuritySchemeCommand = /** @class */ (function (_super) {
    __extends(ChangeSecuritySchemeCommand, _super);
    function ChangeSecuritySchemeCommand(scheme) {
        var _this = this;
        if (((scheme != null && scheme instanceof SecurityScheme) || scheme === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._schemeName === undefined)
                _this._schemeName = null;
            if (_this._schemeObj === undefined)
                _this._schemeObj = null;
            if (_this._oldScheme === undefined)
                _this._oldScheme = null;
            if (_this._schemeName === undefined)
                _this._schemeName = null;
            if (_this._schemeObj === undefined)
                _this._schemeObj = null;
            if (_this._oldScheme === undefined)
                _this._oldScheme = null;
            (function () {
                _this._schemeName = scheme.getName();
                _this._schemeObj = Library.writeNode(scheme);
            })();
        }
        else if (scheme === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._schemeName === undefined)
                _this._schemeName = null;
            if (_this._schemeObj === undefined)
                _this._schemeObj = null;
            if (_this._oldScheme === undefined)
                _this._oldScheme = null;
            if (_this._schemeName === undefined)
                _this._schemeName = null;
            if (_this._schemeObj === undefined)
                _this._schemeObj = null;
            if (_this._oldScheme === undefined)
                _this._oldScheme = null;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    ChangeSecuritySchemeCommand.prototype.execute = function (document) {
        LoggerCompat.info("[ChangeSecuritySchemeCommand] Executing.");
        this._oldScheme = null;
        var scheme = this.getSchemeFromDocument(document);
        if (this.isNullOrUndefined(scheme)) {
            return;
        }
        this._oldScheme = Library.writeNode(scheme);
        this.replaceSchemeWith(scheme, this._schemeObj);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    ChangeSecuritySchemeCommand.prototype.undo = function (document) {
        LoggerCompat.info("[ChangeSecuritySchemeCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldScheme)) {
            return;
        }
        var scheme = this.getSchemeFromDocument(document);
        if (this.isNullOrUndefined(scheme)) {
            return;
        }
        this.nullScheme(scheme);
        Library.readNode(this._oldScheme, scheme);
    };
    /**
     * Replaces the content of a scheme with the content from another scheme.
     * @param {SecurityScheme} toScheme
     * @param {*} fromScheme
     */
    ChangeSecuritySchemeCommand.prototype.replaceSchemeWith = function (toScheme, fromScheme) {
        this.nullScheme(toScheme);
        Library.readNode(fromScheme, toScheme);
    };
    /**
     * Null out all values in the given scheme.
     * @param {SecurityScheme} scheme
     */
    ChangeSecuritySchemeCommand.prototype.nullScheme = function (scheme) {
        scheme.description = null;
        scheme.type = null;
        scheme.name = null;
        scheme.in = null;
    };
    return ChangeSecuritySchemeCommand;
}(AbstractCommand));
export { ChangeSecuritySchemeCommand };
ChangeSecuritySchemeCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ChangeSecuritySchemeCommand";
ChangeSecuritySchemeCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ChangeSecuritySchemeCommand.js.map