import { requireSuperAdmin } from '../../utils/auth'
import { getAllSubscribers } from '../../database/queries/admin'
import { handleApiError, createSuccessResponse } from '../../utils/errors'

export default defineEventHandler(async (event) => {
  try {
    await requireSuperAdmin(event)
    const subscribers = await getAllSubscribers()
    return createSuccessResponse(subscribers, 'Subscribers retrieved successfully')
  } catch (error) {
    throw handleApiError(error)
  }
})
