import { apiRoute } from '@/lib/api/handler'
import { GRID_SCENARIOS, SCENARIO_KEYS } from '@/lib/engine/grid-scenarios'
import { listTwins } from '@/lib/services/twin-service'

export const dynamic = 'force-dynamic'

/**
 * The scenes a viewer can switch between, and the scenarios they can be driven with.
 *
 * The scenes are the twins that already exist — there is no separate 3D scene registry,
 * because a scene that could exist without a twin behind it would be a picture rather
 * than a view of something.
 */
export const GET = apiRoute({ permission: 'twin.read' }, async () => ({
  scenes: (await listTwins()).map((twin) => ({
    code: twin.code,
    level: twin.level,
    name: twin.name,
    nameAr: twin.nameAr,
    regionCode: twin.regionCode,
    assetCode: twin.assetCode,
  })),
  scenarios: SCENARIO_KEYS.map((key) => ({
    key,
    label: GRID_SCENARIOS[key].label,
    labelAr: GRID_SCENARIOS[key].labelAr,
    watchFor: GRID_SCENARIOS[key].watchFor,
    watchForAr: GRID_SCENARIOS[key].watchForAr,
    developsOverMin: GRID_SCENARIOS[key].developsOverMin,
    focusAssetCode: GRID_SCENARIOS[key].focusAssetCode,
  })),
}))
