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 { NodeCompat } from '../../../../../compat/NodeCompat';
import { OasInvalidPropertyValueRule } from './OasInvalidPropertyValueRule';
/**
 * Constructor.
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends OasInvalidPropertyValueRule
 * @author eric.wittmann@gmail.com
 */
var OasServerVarNotFoundInTemplateRule = /** @class */ (function (_super) {
    __extends(OasServerVarNotFoundInTemplateRule, _super);
    function OasServerVarNotFoundInTemplateRule(ruleInfo) {
        return _super.call(this, ruleInfo) || this;
    }
    /**
     * Parses the given server template for variable names.  For example, a server template might be
     *
     * https://{username}.gigantic-server.com:{port}/{basePath}
     *
     * In this case, this method will return [ "username", "port", "basePath" ]
     *
     * @param {string} serverTemplate
     * @return {string[]}
     * @private
     */
    /*private*/ OasServerVarNotFoundInTemplateRule.prototype.parseServerTemplate = function (serverTemplate) {
        var vars = ([]);
        if (!this.hasValue(serverTemplate)) {
            return vars;
        }
        var startIdx = serverTemplate.indexOf("{");
        var endIdx = -1;
        while ((startIdx !== -1)) {
            {
                endIdx = serverTemplate.indexOf('}', startIdx);
                if (endIdx !== -1) {
                    /* add */ (vars.push(serverTemplate.substring(startIdx + 1, endIdx)) > 0);
                    startIdx = serverTemplate.indexOf('{', endIdx);
                }
                else {
                    startIdx = -1;
                }
            }
        }
        ;
        return vars;
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitServerVariable(io.apicurio.datamodels.core.models.common.ServerVariable)
     * @param {ServerVariable} node
     */
    OasServerVarNotFoundInTemplateRule.prototype.visitServerVariable = function (node) {
        var varName = node.getName();
        var server = node.parent();
        var vars = this.parseServerTemplate(server.url);
        var varArray = NodeCompat.asArray(vars);
        this.reportIfInvalid(this.isValidEnumItem(varName, varArray), node, null, this.map("name", varName));
    };
    return OasServerVarNotFoundInTemplateRule;
}(OasInvalidPropertyValueRule));
export { OasServerVarNotFoundInTemplateRule };
OasServerVarNotFoundInTemplateRule["__class"] = "io.apicurio.datamodels.core.validation.rules.invalid.value.OasServerVarNotFoundInTemplateRule";
OasServerVarNotFoundInTemplateRule["__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=OasServerVarNotFoundInTemplateRule.js.map