import { apiRoute } from '@/lib/api/handler'
import { ApiError, ERROR_CODES } from '@/lib/api/errors'
import { listVerifications } from '@/lib/services/verification-service'

export const dynamic = 'force-dynamic'

/** One verification, with its per-channel errors (§7). */
export const GET = apiRoute<{ code: string }>(
  { permission: 'verification.read' },
  async ({ params }) => {
    const rows = await listVerifications({ limit: 200 })
    const found = rows.find((row) => row.code === params.code)
    if (!found) throw new ApiError(ERROR_CODES.notFound)
    return found
  },
)
