import { apiRoute } from '@/lib/api/handler'
import { activeSensorFaults, listSensorsForAssets } from '@/lib/services/sensor-service'

export const dynamic = 'force-dynamic'

/**
 * The instruments on a set of assets, for the scene's sensor layer.
 *
 * A listing, not an assessment: health is per-instrument and needs a reading window, which
 * would make a fleet listing far more expensive than the layer that renders it.
 */
export const GET = apiRoute({ permission: 'twin.read', limit: 120 }, async ({ searchParams }) => {
  const assets = (searchParams.get('assets') ?? '')
    .split(',')
    .map((code) => code.trim())
    .filter(Boolean)
    .slice(0, 300)

  return {
    sensors: await listSensorsForAssets(assets),
    activeFaults: activeSensorFaults(),
  }
})
