import PreRegistration from '../../../models/preRegistration.js'
import { connectDB } from '../../../utils/mongoose.js'

export default defineEventHandler(async (event) => {
  await requireAdmin(event)
  const { ids, status } = await validateBody(event, preRegistrantBulkStatusSchema)
  await connectDB()

  // Only update pre-registrants that aren't already accepted
  const result = await PreRegistration.updateMany(
    { _id: { $in: ids }, status: { $nin: ['accepted'] } },
    { $set: { status } }
  )

  return { modified: result.modifiedCount, total: ids.length }
})
