import { NextResponse } from "next/server";

export const dynamic = "force-dynamic";
export const runtime = "nodejs";

export async function GET(request: Request) {
  const url = new URL(request.url);
  const documentId = url.searchParams.get("documentId")?.trim() || "";
  const workspaceId = url.searchParams.get("workspaceId")?.trim() || "";
  const redirectTo = new URL(
    `/api/page-aggregate/${encodeURIComponent(documentId || ":documentId")}`,
    request.url,
  );
  if (workspaceId) {
    redirectTo.searchParams.set("workspaceId", workspaceId);
  }
  return NextResponse.json(
    {
      error: "Next /api/documents/page compat 读链已退场，请直接使用 /api/page-aggregate/:documentId。",
      redirectTo: redirectTo.pathname + redirectTo.search,
    },
    { status: 410 },
  );
}
