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';
import { NodeCompat } from '../../compat/NodeCompat';
import { Constants } from '../../core/Constants';
/**
 * A command used to delete all security requirements from a document or operation.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteAllSecurityRequirementsCommand = /** @class */ (function (_super) {
    __extends(DeleteAllSecurityRequirementsCommand, _super);
    function DeleteAllSecurityRequirementsCommand(parent) {
        var _this = this;
        if (((parent != null && (parent["__interfaces"] != null && parent["__interfaces"].indexOf("io.apicurio.datamodels.core.models.common.ISecurityRequirementParent") >= 0 || parent.constructor != null && parent.constructor["__interfaces"] != null && parent.constructor["__interfaces"].indexOf("io.apicurio.datamodels.core.models.common.ISecurityRequirementParent") >= 0)) || parent === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldSecurityRequirements === undefined)
                _this._oldSecurityRequirements = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldSecurityRequirements === undefined)
                _this._oldSecurityRequirements = null;
            (function () {
                Library.createNodePath(parent);
            })();
        }
        else if (parent === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldSecurityRequirements === undefined)
                _this._oldSecurityRequirements = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldSecurityRequirements === undefined)
                _this._oldSecurityRequirements = 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
     */
    DeleteAllSecurityRequirementsCommand.prototype.execute = function (document) {
        var _this = this;
        LoggerCompat.info("[DeleteAllSecurityRequirementsCommand] Executing.");
        this._oldSecurityRequirements = ([]);
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        var requirements = parent.getSecurityRequirements();
        if (!this.isNullOrUndefined(requirements)) {
            requirements.forEach(function (req) {
                /* add */ (_this._oldSecurityRequirements.push(Library.writeNode(req)) > 0);
            });
        }
        NodeCompat.setProperty(parent, Constants.PROP_SECURITY, null);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteAllSecurityRequirementsCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteAllSecurityRequirementsCommand] Reverting.");
        if (ModelUtils.isDefined(this._oldSecurityRequirements) && /* size */ this._oldSecurityRequirements.length === 0) {
            return;
        }
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        var requirements = parent.getSecurityRequirements();
        if (this.isNullOrUndefined(requirements)) {
            requirements = ([]);
            NodeCompat.setProperty(parent, Constants.PROP_SECURITY, requirements);
        }
        for (var index192 = 0; index192 < this._oldSecurityRequirements.length; index192++) {
            var oldSecurityRequirement = this._oldSecurityRequirements[index192];
            {
                var requirement = parent.createSecurityRequirement();
                Library.readNode(oldSecurityRequirement, requirement);
                /* add */ (requirements.push(requirement) > 0);
            }
        }
    };
    return DeleteAllSecurityRequirementsCommand;
}(AbstractCommand));
export { DeleteAllSecurityRequirementsCommand };
DeleteAllSecurityRequirementsCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteAllSecurityRequirementsCommand";
DeleteAllSecurityRequirementsCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteAllSecurityRequirementsCommand.js.map