// src/recall-tag-filter.ts
var TAG_MATCH_VALUES = ["any", "all"];
function parseTagMatch(value) {
  if (value === void 0 || value === null) return void 0;
  if (typeof value !== "string") {
    throw new Error(
      `tagMatch must be a string (one of: ${TAG_MATCH_VALUES.join(", ")})`
    );
  }
  const trimmed = value.trim();
  if (trimmed.length === 0) return void 0;
  if (trimmed !== "any" && trimmed !== "all") {
    throw new Error(
      `invalid tagMatch value: ${value} (expected one of: ${TAG_MATCH_VALUES.join(", ")})`
    );
  }
  return trimmed;
}
function normalizeTags(value) {
  if (!Array.isArray(value)) return void 0;
  const out = [];
  const seen = /* @__PURE__ */ new Set();
  for (const entry of value) {
    if (typeof entry !== "string") continue;
    const trimmed = entry.trim();
    if (trimmed.length === 0) continue;
    if (seen.has(trimmed)) continue;
    seen.add(trimmed);
    out.push(trimmed);
  }
  return out.length > 0 ? out : void 0;
}
function evaluateTagFilter(candidateTags, filter) {
  const filterTags = filter.tags;
  if (!filterTags || filterTags.length === 0) {
    return { admitted: true };
  }
  const tags = Array.isArray(candidateTags) ? candidateTags : [];
  const tagSet = new Set(tags);
  const mode = filter.tagMatch ?? "any";
  if (mode === "all") {
    for (const t of filterTags) {
      if (!tagSet.has(t)) return { admitted: false };
    }
    return { admitted: true };
  }
  for (const t of filterTags) {
    if (tagSet.has(t)) return { admitted: true };
  }
  return { admitted: false };
}
function applyTagFilter(results, filter) {
  const filterTags = filter.tags;
  if (!filterTags || filterTags.length === 0) {
    return { results, trace: null };
  }
  const mode = filter.tagMatch ?? "any";
  const admitted = [];
  for (const r of results) {
    if (evaluateTagFilter(r.tags, filter).admitted) {
      admitted.push(r);
    }
  }
  const trace = {
    name: "tag-filter",
    considered: results.length,
    admitted: admitted.length,
    reason: `tags=${filterTags.join(",")} match=${mode}`
  };
  return { results: admitted, trace };
}

export {
  parseTagMatch,
  normalizeTags,
  evaluateTagFilter,
  applyTagFilter
};
//# sourceMappingURL=chunk-BT7NVCML.js.map