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 __());
    };
})();
import { OasInvalidPropertyValueRule } from './OasInvalidPropertyValueRule';
/**
 * Constructor.
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends OasInvalidPropertyValueRule
 * @author eric.wittmann@gmail.com
 */
var OasUnexpectedSecurityRequirementScopesRule = /** @class */ (function (_super) {
    __extends(OasUnexpectedSecurityRequirementScopesRule, _super);
    function OasUnexpectedSecurityRequirementScopesRule(ruleInfo) {
        return _super.call(this, ruleInfo) || this;
    }
    /**
     * Returns true if the given required scopes are all actually defined by the security definition.
     * @param {string[]} requiredScopes
     * @param {Oas20Scopes} definedScopes
     * @return {boolean}
     */
    OasUnexpectedSecurityRequirementScopesRule.prototype.isValidScopes = function (requiredScopes, definedScopes) {
        var rval = true;
        var dscopes = ([]);
        if (this.hasValue(definedScopes)) {
            dscopes = definedScopes.getScopeNames();
        }
        for (var index148 = 0; index148 < requiredScopes.length; index148++) {
            var requiredScope = requiredScopes[index148];
            {
                if (dscopes.indexOf(requiredScope) === -1) {
                    rval = false;
                }
            }
        }
        return rval;
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
     * @param {SecurityRequirement} node
     */
    OasUnexpectedSecurityRequirementScopesRule.prototype.visitSecurityRequirement = function (node) {
        var _this = this;
        var snames = node.getSecurityRequirementNames();
        snames.forEach(function (sname) {
            var sdefs = node.ownerDocument().securityDefinitions;
            if (_this.hasValue(sdefs)) {
                var scheme = sdefs.getSecurityScheme(sname);
                if (_this.hasValue(scheme)) {
                    if (_this.equals(scheme.type, "oauth2")) {
                        var definedScopes = scheme.scopes;
                        var requiredScopes = node.getScopes(sname);
                        _this.reportIfInvalid(_this.isValidScopes(requiredScopes, definedScopes), node, null, _this.map("sname", sname));
                    }
                }
            }
        });
    };
    return OasUnexpectedSecurityRequirementScopesRule;
}(OasInvalidPropertyValueRule));
export { OasUnexpectedSecurityRequirementScopesRule };
OasUnexpectedSecurityRequirementScopesRule["__class"] = "io.apicurio.datamodels.core.validation.rules.invalid.value.OasUnexpectedSecurityRequirementScopesRule";
OasUnexpectedSecurityRequirementScopesRule["__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=OasUnexpectedSecurityRequirementScopesRule.js.map