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

export default defineEventHandler(async (event) => {
  const admin = await requireAdmin(event)
  await connectDB()

  const rows = await AdminAlertDismissal.find({ adminId: admin._id.toString() })
    .sort({ dismissedAt: -1 })
    .lean()

  const dismissed = rows
    .filter((r) => ALERT_METADATA[r.alertType]) // defensive: skip any orphaned legacy slugs
    .map((r) => ({
      alertType: r.alertType,
      title: ALERT_METADATA[r.alertType].title,
      severity: ALERT_METADATA[r.alertType].severity,
      dismissedAt: r.dismissedAt
    }))

  return { dismissed }
})
