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 { VisitorUtil } from '../../../../util/VisitorUtil';
import { OperationFinder } from '../../../../visitors/OperationFinder';
import { TraverserDirection } from '../../../../visitors/TraverserDirection';
import { OasInvalidPropertyNameRule } from './OasInvalidPropertyNameRule';
/**
 * Constructor.
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends OasInvalidPropertyNameRule
 * @author eric.wittmann@gmail.com
 */
var OasUnmatchedExampleTypeRule = /** @class */ (function (_super) {
    __extends(OasUnmatchedExampleTypeRule, _super);
    function OasUnmatchedExampleTypeRule(ruleInfo) {
        return _super.call(this, ruleInfo) || this;
    }
    /**
     * Finds the parent operation for the given node.
     * @param example
     * @param {Node} node
     * @return {Operation}
     * @private
     */
    /*private*/ OasUnmatchedExampleTypeRule.findParentOperation = function (node) {
        var finder = new OperationFinder();
        VisitorUtil.visitTree(node, finder, TraverserDirection.up);
        return finder.found;
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
     * @param {*} node
     */
    OasUnmatchedExampleTypeRule.prototype.visitExample = function (node) {
        var example20 = node;
        var doc = example20.ownerDocument();
        var produces = doc.produces;
        var operation = OasUnmatchedExampleTypeRule.findParentOperation(example20);
        if (this.hasValue(operation.produces)) {
            produces = operation.produces;
        }
        if (!this.hasValue(produces)) {
            produces = ([]);
        }
        var ctypes = example20.getExampleContentTypes();
        for (var index145 = 0; index145 < ctypes.length; index145++) {
            var ct = ctypes[index145];
            {
                this.reportIfInvalid(produces.indexOf(ct) !== -1, example20, Constants.PROP_PRODUCES, this.map("contentType", ct));
            }
        }
    };
    return OasUnmatchedExampleTypeRule;
}(OasInvalidPropertyNameRule));
export { OasUnmatchedExampleTypeRule };
OasUnmatchedExampleTypeRule["__class"] = "io.apicurio.datamodels.core.validation.rules.invalid.name.OasUnmatchedExampleTypeRule";
OasUnmatchedExampleTypeRule["__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=OasUnmatchedExampleTypeRule.js.map