import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";

export async function GET(_: Request, context: { params: Promise<{ id: string }> }) {
  const { id } = await context.params;
  const comments = await prisma.comment.findMany({
    where: { postId: id },
    orderBy: { createdAt: "asc" },
    select: {
      id: true,
      content: true,
      isAnonymous: true,
      isSecret: true,
      secretPasswordHash: true,
      createdAt: true,
    },
  });
  const presented = comments.map((c) => ({
    id: c.id,
    content: c.isSecret ? "비밀댓글입니다." : c.content,
    isAnonymous: c.isAnonymous,
    isSecret: c.isSecret,
    anonId: c.isAnonymous ? c.id.slice(-6) : undefined,
    createdAt: c.createdAt,
  }));
  return NextResponse.json({ comments: presented });
}


