import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { getCardActivity } from "@/lib/activity-log";
import { requireApiAuthWithOrg, handleApiError } from "@/lib/api-auth";

export async function GET(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    const session = await requireApiAuthWithOrg();
    const { id } = await params;

    const card = await prisma.responseCard.findUnique({ where: { id }, select: { organizationId: true } });
    if (!card || card.organizationId !== session.user.orgId) {
      return NextResponse.json({ error: "Card not found" }, { status: 404 });
    }

    const activity = await getCardActivity(id);
    return NextResponse.json(activity);
  } catch (error) {
    return handleApiError(error);
  }
}
