import { revalidateTag } from 'next/cache'

/**
 * Returns a Payload hook that invalidates a Next cache tag.
 *
 * Safe to use for docs created/deleted programmatically (e.g. by
 * regenerateMassesForChurch / regenerateOccurrencesForEvent), since the
 * Local API runs collection hooks. The jobs queue can execute outside a
 * Next request scope where revalidateTag throws — swallow that; the
 * fetch-side TTL covers the gap there.
 */
export const revalidateTagHook = (tag: string) => () => {
  try {
    revalidateTag(tag)
  } catch {}
}
