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 { ReferenceUtil } from '../../../../util/ReferenceUtil';
import { VisitorUtil } from '../../../../util/VisitorUtil';
import { PathItemFinder } from '../../../../visitors/PathItemFinder';
import { TraverserDirection } from '../../../../visitors/TraverserDirection';
import { OasInvalidPropertyValueRule } from './OasInvalidPropertyValueRule';
/**
 * Constructor.
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends OasInvalidPropertyValueRule
 * @author eric.wittmann@gmail.com
 */
var OasPathParamNotFoundRule = /** @class */ (function (_super) {
    __extends(OasPathParamNotFoundRule, _super);
    function OasPathParamNotFoundRule(ruleInfo) {
        return _super.call(this, ruleInfo) || this;
    }
    OasPathParamNotFoundRule.findPathItem = function (node) {
        var finder = new PathItemFinder();
        VisitorUtil.visitTree(node, finder, TraverserDirection.up);
        return finder.found;
    };
    OasPathParamNotFoundRule.prototype.hasPathParamSegment = function (segments, paramName) {
        for (var index147 = 0; index147 < segments.length; index147++) {
            var seg = segments[index147];
            {
                if (this.equals(seg.formalName, paramName)) {
                    return true;
                }
            }
        }
        return false;
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitParameter(io.apicurio.datamodels.core.models.common.Parameter)
     * @param {Parameter} node
     */
    OasPathParamNotFoundRule.prototype.visitParameter = function (node) {
        var resolvedParam = ReferenceUtil.resolveNodeRef$io_apicurio_datamodels_core_models_Node(node);
        if (this.hasValue(resolvedParam) && this.equals(resolvedParam.in, "path")) {
            var pathItem = OasPathParamNotFoundRule.findPathItem(node);
            var path = pathItem.getPath();
            var pathSegs = this.getPathSegments(path);
            this.reportIf(!this.hasPathParamSegment(pathSegs, resolvedParam.name), node, Constants.PROP_NAME, this.map("name", resolvedParam.name));
        }
    };
    return OasPathParamNotFoundRule;
}(OasInvalidPropertyValueRule));
export { OasPathParamNotFoundRule };
OasPathParamNotFoundRule["__class"] = "io.apicurio.datamodels.core.validation.rules.invalid.value.OasPathParamNotFoundRule";
OasPathParamNotFoundRule["__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=OasPathParamNotFoundRule.js.map