import { authenticateApiRequest } from '@/lib/api-auth'
import { getSoloWorkspaceSnapshot } from '@/lib/solo-workspace-server'

export const dynamic = 'force-dynamic'

export async function GET(
  request: Request,
  { params }: { params: Promise<{ id: string }> },
) {
  const auth = await authenticateApiRequest(request)
  if ('error' in auth) {
    return Response.json({ error: auth.error }, { status: auth.status })
  }

  const { id } = await params
  const url = new URL(request.url)
  const sprintId = url.searchParams.get('sprint_id')
  const snapshot = await getSoloWorkspaceSnapshot(id, auth.userId, sprintId)

  if (!snapshot) {
    return Response.json({ error: 'Solo workspace niet gevonden' }, { status: 404 })
  }

  return Response.json(snapshot)
}
