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 { LoggerCompat } from '../../compat/LoggerCompat';
import { SecurityScheme } from '../../core/models/common/SecurityScheme';
import { NewSecuritySchemeCommand } from './NewSecuritySchemeCommand';
/**
 * @author eric.wittmann@gmail.com
 * @extends NewSecuritySchemeCommand
 * @class
 */
var NewSecuritySchemeCommand_20 = /** @class */ (function (_super) {
    __extends(NewSecuritySchemeCommand_20, _super);
    function NewSecuritySchemeCommand_20(scheme) {
        var _this = this;
        if (((scheme != null && scheme instanceof SecurityScheme) || scheme === null)) {
            var __args = arguments;
            _this = _super.call(this, scheme) || this;
            if (_this._nullSecurityDefinitions === undefined)
                _this._nullSecurityDefinitions = false;
            if (_this._nullSecurityDefinitions === undefined)
                _this._nullSecurityDefinitions = false;
        }
        else if (scheme === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._nullSecurityDefinitions === undefined)
                _this._nullSecurityDefinitions = false;
            if (_this._nullSecurityDefinitions === undefined)
                _this._nullSecurityDefinitions = 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
     */
    NewSecuritySchemeCommand_20.prototype.execute = function (document) {
        LoggerCompat.info("[NewSecuritySchemeCommand] Executing.");
        var doc20 = document;
        this._nullSecurityDefinitions = false;
        if (this.isNullOrUndefined(doc20.securityDefinitions)) {
            doc20.securityDefinitions = doc20.createSecurityDefinitions();
            this._nullSecurityDefinitions = true;
        }
        if (this.isNullOrUndefined(doc20.securityDefinitions.getSecurityScheme(this._schemeName))) {
            var scheme = doc20.securityDefinitions.createSecurityScheme(this._schemeName);
            Library.readNode(this._scheme, scheme);
            doc20.securityDefinitions.addSecurityScheme(this._schemeName, scheme);
            this._schemeExisted = false;
        }
        else {
            this._schemeExisted = true;
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewSecuritySchemeCommand_20.prototype.undo = function (document) {
        LoggerCompat.info("[NewSecuritySchemeCommand] Reverting.");
        if (this._schemeExisted) {
            return;
        }
        var doc20 = document;
        if (this._nullSecurityDefinitions) {
            doc20.securityDefinitions = null;
            return;
        }
        doc20.securityDefinitions.removeSecurityScheme(this._schemeName);
    };
    return NewSecuritySchemeCommand_20;
}(NewSecuritySchemeCommand));
export { NewSecuritySchemeCommand_20 };
NewSecuritySchemeCommand_20["__class"] = "io.apicurio.datamodels.cmd.commands.NewSecuritySchemeCommand_20";
NewSecuritySchemeCommand_20["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewSecuritySchemeCommand_20.js.map