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 { RegexCompat } from '../../../../../compat/RegexCompat';
import { ValidationRule } from '../../../ValidationRule';
/**
 * Constructor.
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends ValidationRule
 * @author eric.wittmann@gmail.com
 */
var OasInvalidPropertyNameRule = /** @class */ (function (_super) {
    __extends(OasInvalidPropertyNameRule, _super);
    function OasInvalidPropertyNameRule(ruleInfo) {
        return _super.call(this, ruleInfo) || this;
    }
    /**
     * Returns true if the definition name is valid.
     * @param {string} name
     * @return {boolean}
     */
    OasInvalidPropertyNameRule.prototype.isValidDefinitionName = function (name) {
        return RegexCompat.matches(name, OasInvalidPropertyNameRule.DEFINITION_NAME_MATCH_REGEX);
    };
    /**
     * Returns true if the scope name is valid.
     * @param {string} scope
     * @return {boolean}
     */
    OasInvalidPropertyNameRule.prototype.isValidScopeName = function (scope) {
        return true;
    };
    /**
     * Finds all occurences of path segments that are empty.
     * i.e. they neither have a prefix nor a path variable within curly braces.
     *
     * @param {ValidationRule.PathSegment[]} pathSegments
     * @return {ValidationRule.PathSegment[]}
     */
    OasInvalidPropertyNameRule.prototype.findEmptySegmentsInPath = function (pathSegments) {
        var emptySegments = ([]);
        for (var index146 = 0; index146 < pathSegments.length; index146++) {
            var pathSegment = pathSegments[index146];
            {
                if (this.equals(pathSegment.prefix, "") && !this.hasValue(pathSegment.formalName)) {
                    /* add */ (emptySegments.push(pathSegment) > 0);
                }
            }
        }
        return emptySegments;
    };
    /**
     * Finds path segments that are duplicates i.e. they have the same formal name used across multiple segments.
     * For example, in a path like /prefix/{var1}/{var1}, var1 is used in multiple segments.
     *
     * @param {ValidationRule.PathSegment[]} pathSegments
     * @return {string[]}
     */
    OasInvalidPropertyNameRule.prototype.findDuplicateParametersInPath = function (pathSegments) {
        var _this = this;
        var counts = ({});
        pathSegments.forEach((function (counts) {
            return function (pathSegment) {
                if (_this.hasValue(pathSegment.formalName)) {
                    var count = 0;
                    if ( /* containsKey */counts.hasOwnProperty(pathSegment.formalName)) {
                        count = /* get */ (function (m, k) { return m[k] === undefined ? null : m[k]; })(counts, pathSegment.formalName);
                    }
                    /* put */ (counts[pathSegment.formalName] = count + 1);
                }
            };
        })(counts));
        var rval = ([]);
        {
            var array148 = /* entrySet */ (function (o) { var s = []; for (var e in o)
                s.push({ k: e, v: o[e], getKey: function () { return this.k; }, getValue: function () { return this.v; } }); return s; })(counts);
            for (var index147 = 0; index147 < array148.length; index147++) {
                var entry = array148[index147];
                {
                    if (entry.getValue() > 1) {
                        /* add */ (rval.push(entry.getKey()) > 0);
                    }
                }
            }
        }
        return rval;
    };
    OasInvalidPropertyNameRule.DEFINITION_NAME_MATCH_REGEX = "^[a-zA-Z0-9\\.\\-_]+$";
    return OasInvalidPropertyNameRule;
}(ValidationRule));
export { OasInvalidPropertyNameRule };
OasInvalidPropertyNameRule["__class"] = "io.apicurio.datamodels.core.validation.rules.invalid.name.OasInvalidPropertyNameRule";
OasInvalidPropertyNameRule["__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=OasInvalidPropertyNameRule.js.map