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 { DocumentType } from '../../../../models/DocumentType';
import { OasInvalidPropertyValueRule } from './OasInvalidPropertyValueRule';
/**
 * Constructor.
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends OasInvalidPropertyValueRule
 * @author eric.wittmann@gmail.com
 */
var OasSecurityRequirementScopesMustBeEmptyRule = /** @class */ (function (_super) {
    __extends(OasSecurityRequirementScopesMustBeEmptyRule, _super);
    function OasSecurityRequirementScopesMustBeEmptyRule(ruleInfo) {
        return _super.call(this, ruleInfo) || this;
    }
    /*private*/ OasSecurityRequirementScopesMustBeEmptyRule.prototype.findSecurityScheme = function (document, schemeName) {
        if (document.is2xDocument()) {
            var doc20 = document;
            if (this.hasValue(doc20.securityDefinitions)) {
                return doc20.securityDefinitions.getSecurityScheme(schemeName);
            }
        }
        else {
            var doc30 = document;
            if (this.hasValue(doc30.components)) {
                return doc30.components.getSecurityScheme(schemeName);
            }
        }
        return null;
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
     * @param {SecurityRequirement} node
     */
    OasSecurityRequirementScopesMustBeEmptyRule.prototype.visitSecurityRequirement = function (node) {
        var allowedTypes = ([]);
        /* add */ (allowedTypes.push("oauth2") > 0);
        var options = "\"oauth2\"";
        if (node.ownerDocument().getDocumentType() === DocumentType.openapi3) {
            /* add */ (allowedTypes.push("openIdConnect") > 0);
            options = "\"oauth2\" or \"openIdConnect\"";
        }
        var snames = node.getSecurityRequirementNames();
        for (var index157 = 0; index157 < snames.length; index157++) {
            var sname = snames[index157];
            {
                var scheme = this.findSecurityScheme(node.ownerDocument(), sname);
                if (this.hasValue(scheme)) {
                    if (allowedTypes.indexOf(scheme.type) === -1) {
                        var scopes = node.getScopes(sname);
                        this.reportIfInvalid(this.hasValue(scopes) && /* size */ scopes.length === 0, node, null, this.map("sname", sname, "options", options));
                    }
                }
            }
        }
    };
    return OasSecurityRequirementScopesMustBeEmptyRule;
}(OasInvalidPropertyValueRule));
export { OasSecurityRequirementScopesMustBeEmptyRule };
OasSecurityRequirementScopesMustBeEmptyRule["__class"] = "io.apicurio.datamodels.core.validation.rules.invalid.value.OasSecurityRequirementScopesMustBeEmptyRule";
OasSecurityRequirementScopesMustBeEmptyRule["__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=OasSecurityRequirementScopesMustBeEmptyRule.js.map