import AdminAlertDismissal from '../../../models/adminAlertDismissal.js'
import { connectDB } from '../../../utils/mongoose.js'

export default defineEventHandler(async (event) => {
  const admin = await requireAdmin(event)
  const { alertType, signature } = await validateBody(event, adminAlertDismissSchema)
  await connectDB()

  await AdminAlertDismissal.findOneAndUpdate(
    { adminId: admin._id.toString(), alertType },
    { $set: { signature, dismissedAt: new Date() } },
    { upsert: true, new: true }
  )

  return { ok: true }
})
