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 { Constants } from '../../../Constants';
import { ValidationRule } from '../../ValidationRule';
/**
 * Constructor.
 *
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends ValidationRule
 * @author cfoskin@redhat.com
 */
var SecurityRequirementUniquenessValidationRule = /** @class */ (function (_super) {
    __extends(SecurityRequirementUniquenessValidationRule, _super);
    function SecurityRequirementUniquenessValidationRule(ruleInfo) {
        return _super.call(this, ruleInfo) || this;
    }
    /**
     * @param {SecurityRequirement} currentSecurityRequirement
     * @param {SecurityRequirement} otherSecurityRequirement
     * @return {boolean} returns true if the two security requirements are equal
     * @private
     */
    /*private*/ SecurityRequirementUniquenessValidationRule.isEqualTo = function (currentSecurityRequirement, otherSecurityRequirement) {
        var currentSecurityRequirementNames = currentSecurityRequirement.getSecurityRequirementNames();
        var otherSecurityRequirementNames = otherSecurityRequirement.getSecurityRequirementNames();
        /* sort */ currentSecurityRequirementNames.sort();
        /* sort */ otherSecurityRequirementNames.sort();
        if (!(function (a1, a2) { if (a1 == null && a2 == null)
            return true; if (a1 == null || a2 == null)
            return false; if (a1.length != a2.length)
            return false; for (var i = 0; i < a1.length; i++) {
            if (a1[i] != a2[i])
                return false;
        } return true; })(currentSecurityRequirementNames, otherSecurityRequirementNames)) {
            return false;
        }
        for (var index153 = 0; index153 < currentSecurityRequirementNames.length; index153++) {
            var secReqName = currentSecurityRequirementNames[index153];
            {
                var secReqScopes = currentSecurityRequirement.getScopes(secReqName);
                var otherSecReqScopes = otherSecurityRequirement.getScopes(secReqName);
                /* sort */ secReqScopes.sort();
                /* sort */ otherSecReqScopes.sort();
                if (!(function (a1, a2) { if (a1 == null && a2 == null)
                    return true; if (a1 == null || a2 == null)
                    return false; if (a1.length != a2.length)
                    return false; for (var i = 0; i < a1.length; i++) {
                    if (a1[i] != a2[i])
                        return false;
                } return true; })(secReqScopes, otherSecReqScopes)) {
                    return false;
                }
            }
        }
        return true;
    };
    /**
     * @param {SecurityRequirement} currentSecurityRequirement
     * @param {SecurityRequirement[]} allRequirements
     * @return {boolean} true if duplicates are found
     * @private
     */
    /*private*/ SecurityRequirementUniquenessValidationRule.checkForDuplicates = function (currentSecurityRequirement, allRequirements) {
        var clonedList = (allRequirements.slice(0));
        /* remove */ (function (a) { var index = a.indexOf(currentSecurityRequirement); if (index >= 0) {
            a.splice(index, 1);
            return true;
        }
        else {
            return false;
        } })(clonedList);
        for (var index154 = 0; index154 < clonedList.length; index154++) {
            var otherSecurityRequirement = clonedList[index154];
            {
                if (SecurityRequirementUniquenessValidationRule.isEqualTo(currentSecurityRequirement, otherSecurityRequirement)) {
                    return true;
                }
            }
        }
        return false;
    };
    /**
     * @param {SecurityRequirement} node
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
     */
    SecurityRequirementUniquenessValidationRule.prototype.visitSecurityRequirement = function (node) {
        var parent = node.parent();
        var securityRequirements = parent.getSecurityRequirements();
        if ( /* size */securityRequirements.length <= 1) {
            return;
        }
        if (SecurityRequirementUniquenessValidationRule.checkForDuplicates(node, securityRequirements)) {
            this.report(node, Constants.PROP_SECURITY, this.map("securityReq", /* toString */ ('[' + node.getSecurityRequirementNames().join(', ') + ']')));
        }
    };
    return SecurityRequirementUniquenessValidationRule;
}(ValidationRule));
export { SecurityRequirementUniquenessValidationRule };
SecurityRequirementUniquenessValidationRule["__class"] = "io.apicurio.datamodels.core.validation.rules.other.SecurityRequirementUniquenessValidationRule";
SecurityRequirementUniquenessValidationRule["__interfaces"] = ["io.apicurio.datamodels.core.visitors.IVisitor", "io.apicurio.datamodels.asyncapi.v2.visitors.IAai20Visitor", "io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor", "io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor", "io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor", "io.apicurio.datamodels.openapi.visitors.IOasVisitor"];
//# sourceMappingURL=SecurityRequirementUniquenessValidationRule.js.map