"use server";
import { revalidatePath, revalidateTag } from "next/cache";
import { clearApiCache } from "@/utils/api-server";
import { ALL_CONTENT_TAGS } from "@/utils/cacheTags";

export async function setRevalidate(
  path: string,
  tags: string[] = ALL_CONTENT_TAGS
) {
  // Content changed on the backend (socket broadcast): clear this instance's
  // in-memory axios cache (serves the non-tagged detail pages) and invalidate
  // ONLY the tags the event touched — so a news post no longer wipes
  // settings/website-data and re-crushes the origin. Callers pass the specific
  // tag; the default stays "everything" for any caller that can't tell.
  await clearApiCache();
  for (const tag of tags) revalidateTag(tag);
  revalidatePath(path, "page");
}
