import { apiRoute } from '@/lib/api/handler'
import { ApiError, ERROR_CODES } from '@/lib/api/errors'
import { getHunt } from '@/lib/services/risk-hunter-service'

export const dynamic = 'force-dynamic'

/** One hunt, with its findings, preventions and break points. */
export const GET = apiRoute<{ code: string }>(
  { permission: 'riskhunter.read' },
  async ({ params }) => {
    const hunt = await getHunt(params.code)
    if (!hunt) throw new ApiError(ERROR_CODES.notFound)
    return hunt
  },
)
