// RootTale 발행 웹훅 수신 — ES256 서명 검증 후 Next.js 캐시 revalidate.
// 어드민 "내 사이트 > 배포"에 https://<도메인>/api/revalidate 로 등록한다.
import { revalidatePath } from "next/cache";
import { createRevalidateRoute } from "@roottale/cms-renderer-next/routes";

function revalidateBlogPath(path: string): void {
  revalidatePath(path);
  // 카테고리/태그 인덱스 같은 동적 경로가 있으면 함께 무효화
  // if (path === "/blog/categories") revalidatePath("/blog/categories/[category]", "page");
}

export const POST = createRevalidateRoute({
  apiKey: process.env.ROOTTALE_API_KEY!,
  apiBase: process.env.ROOTTALE_API_BASE,
  revalidate: revalidateBlogPath,
  // 홈에 최신 글 섹션이 있으면 "/" 포함 — 글 변경 시 홈도 함께 갱신
  alsoRevalidate: ["/feed.xml", "/sitemap.xml", "/blog", "/"],
});

export function GET(): Response {
  return new Response("Method Not Allowed", { status: 405 });
}
