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 { DocumentType } from '../../../../models/DocumentType';
import { ValidationRule } from '../../../ValidationRule';
/**
 * Constructor.
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends ValidationRule
 * @author eric.wittmann@gmail.com
 */
var OasInvalidSecurityRequirementNameRule = /** @class */ (function (_super) {
    __extends(OasInvalidSecurityRequirementNameRule, _super);
    function OasInvalidSecurityRequirementNameRule(ruleInfo) {
        return _super.call(this, ruleInfo) || this;
    }
    /**
     * Returns true if the security requirement name is valid.  It does this by looking up a declared
     * security scheme definition in the document.  If no security scheme definition exists with the
     * given name, then it is invalid.
     * @param {string} securityReqName
     * @param {Document} doc
     * @return {boolean}
     * @private
     */
    /*private*/ OasInvalidSecurityRequirementNameRule.prototype.isValidSecurityRequirementName = function (securityReqName, doc) {
        var dt = doc.getDocumentType();
        if (dt === DocumentType.openapi2) {
            var doc20 = doc;
            return this.hasValue(doc20.securityDefinitions) && this.isDefined(doc20.securityDefinitions.getSecurityScheme(securityReqName));
        }
        else if (dt === DocumentType.openapi3) {
            var doc30 = doc;
            return this.hasValue(doc30.components) && this.isDefined(doc30.components.getSecurityScheme(securityReqName));
        }
        else if (dt === DocumentType.asyncapi2) {
        }
        return false;
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
     * @param {SecurityRequirement} node
     */
    OasInvalidSecurityRequirementNameRule.prototype.visitSecurityRequirement = function (node) {
        var _this = this;
        node.getSecurityRequirementNames().forEach(function (name) {
            _this.reportIfInvalid(_this.isValidSecurityRequirementName(name, node.ownerDocument()), node, null, _this.map("name", name));
        });
    };
    return OasInvalidSecurityRequirementNameRule;
}(ValidationRule));
export { OasInvalidSecurityRequirementNameRule };
OasInvalidSecurityRequirementNameRule["__class"] = "io.apicurio.datamodels.core.validation.rules.invalid.reference.OasInvalidSecurityRequirementNameRule";
OasInvalidSecurityRequirementNameRule["__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=OasInvalidSecurityRequirementNameRule.js.map