'use strict';

var chunkKSN5CWZ7_cjs = require('./chunk-KSN5CWZ7.cjs');
var chunkHDIYJI2Z_cjs = require('./chunk-HDIYJI2Z.cjs');

// src/server/handlers/favorites-enrichment.ts
async function prepareFavoritesEnrichment(mastra, requestContext, entityType, entityIds) {
  if (!await chunkKSN5CWZ7_cjs.isBuilderFeatureEnabled(mastra, "favorites")) return null;
  const userId = chunkHDIYJI2Z_cjs.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);
}

exports.enrichOrStripFavorites = enrichOrStripFavorites;
exports.prepareFavoritesEnrichment = prepareFavoritesEnrichment;
exports.stripFavoriteFields = stripFavoriteFields;
//# sourceMappingURL=chunk-ULYIMS6J.cjs.map
//# sourceMappingURL=chunk-ULYIMS6J.cjs.map