import { NextResponse } from "next/server";
import { readDocument, listPages } from "@/lib/wiki";

export async function GET(_req: Request, ctx: { params: Promise<{ docId: string }> }) {
  const { docId } = await ctx.params;
  const doc = await readDocument(docId);
  if (!doc) return NextResponse.json({ error: "not_found" }, { status: 404 });
  const pages = await listPages(docId);
  return NextResponse.json({
    doc_id: docId,
    frontmatter: doc.fm,
    body: doc.body,
    pages,
  });
}
