import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { safeHandler, requireAuth, AuthError } from '@/lib/auth'

export const GET = safeHandler(async (_req: Request, { params }: { params: Promise<{ id: string; revisionId: string }> }) => {
  await requireAuth()
  const { revisionId } = await params

  const revision = await prisma.quoteRevision.findUnique({
    where: { id: revisionId },
    include: {
      changedBy: { select: { name: true } },
    },
  })
  if (!revision) throw new AuthError('Revision not found', 404)

  return NextResponse.json({
    ...revision,
    snapshotData: JSON.parse(revision.snapshotData),
  })
})
