import { matchWildcardPattern } from "@open-mercato/shared/lib/patterns/wildcard";
function matchEventPattern(eventName, pattern, options) {
  const mode = options?.mode ?? "single-segment";
  if (pattern === "*") return true;
  if (pattern === eventName) return true;
  if (!pattern.includes("*")) return false;
  if (mode === "prefix") {
    if (pattern.endsWith(".*")) {
      const prefix = pattern.slice(0, -2);
      return eventName.startsWith(prefix + ".");
    }
    if (pattern.endsWith("*")) {
      const prefix = pattern.slice(0, -1);
      return eventName.startsWith(prefix);
    }
    return false;
  }
  return matchWildcardPattern(eventName, pattern, { singleSegmentWildcard: true });
}
function matchAnyEventPattern(eventName, patterns, options) {
  for (const pattern of patterns) {
    if (matchEventPattern(eventName, pattern, options)) {
      return true;
    }
  }
  return false;
}
function matchWebhookEventPattern(eventName, pattern) {
  return matchEventPattern(eventName, pattern, { mode: "prefix" });
}
function matchAnyWebhookEventPattern(eventName, patterns) {
  return matchAnyEventPattern(eventName, patterns, { mode: "prefix" });
}
export {
  matchAnyEventPattern,
  matchAnyWebhookEventPattern,
  matchEventPattern,
  matchWebhookEventPattern
};
//# sourceMappingURL=patterns.js.map
