import { apiRoute } from '@/lib/api/handler'
import { getDeviations } from '@/lib/services/twin-service'

export const dynamic = 'force-dynamic'

/** Where the twin and the instruments disagree, and which one is suspected (§33). */
export const GET = apiRoute<{ code: string }>(
  { permission: 'twin.read' },
  async ({ params, searchParams }) => {
    const limit = Math.min(30, Math.max(1, Number(searchParams.get('limit')) || 12))
    const deviations = await getDeviations(params.code, { limit })
    return { deviations, threshold: 6 }
  },
)
