import { isBuilderFeatureEnabled } from './chunk-M6GURVJO.js';
import { getCallerAuthorId } from './chunk-SXZS6VZ3.js';

// src/server/handlers/favorites-enrichment.ts
async function prepareFavoritesEnrichment(mastra, requestContext, entityType, entityIds) {
  if (!await isBuilderFeatureEnabled(mastra, "favorites")) return null;
  const userId = getCallerAuthorId(requestContext);
  if (!userId) return null;
  const storage = mastra.getStorage();
  if (!storage) return null;
  const favoritesStore = await storage.getStore("favorites");
  if (!favoritesStore) return null;
  const starredIds = entityIds.length === 0 ? /* @__PURE__ */ new Set() : await favoritesStore.isFavoritedBatch({ userId, entityType, entityIds });
  return { userId, starredIds, favoritesStore };
}
function stripFavoriteFields(record) {
  if ("isFavorited" in record || "favoriteCount" in record) {
    const copy = { ...record };
    delete copy.isFavorited;
    delete copy.favoriteCount;
    return copy;
  }
  return record;
}
async function enrichOrStripFavorites(mastra, requestContext, entityType, record) {
  const enrichment = await prepareFavoritesEnrichment(mastra, requestContext, entityType, [record.id]);
  if (enrichment) {
    return { ...record, isFavorited: enrichment.starredIds.has(record.id) };
  }
  return stripFavoriteFields(record);
}

export { enrichOrStripFavorites, prepareFavoritesEnrichment, stripFavoriteFields };
//# sourceMappingURL=chunk-VB4SJ6UF.js.map
//# sourceMappingURL=chunk-VB4SJ6UF.js.map