import api from './axios'

export const notificationsApi = {
  // Get all notifications
  getAllNotifications: (page = 1, perPage = 10, type = 'all') => {
    return api.get('/admin/notifications/all', { params: { page, per_page: perPage, type } })
  },

  // Mark a notification as read
  markAsRead: (id) => {
    return api.post(`/admin/notifications/${id}/read`)
  },

  /**
   * Mark multiple notifications as read by IDs
   * Expects payload { notification_ids: [] }
   */
  markAllAsRead: (notificationIds = []) => {
    return api.post('/admin/notifications/read-all', { notification_ids: notificationIds })
  },

  // Delete a notification
  deleteNotification: (id) => {
    return api.delete(`/admin/notifications/${id}`)
  },

  /**
   * Bulk delete notifications by IDs
   * Expects payload { notification_ids: [] }
   */
  clearAll: (notificationIds = []) => {
    return api.delete('/admin/notifications', { data: { notification_ids: notificationIds } })
  },
  // Get unread notifications count
  count: () => {
    return api.get('/admin/notifications/count')
  },
  // alias to markAllAsRead for backward compatibility
  bulkMarkAsRead(notificationIds) {
    return this.markAllAsRead(notificationIds)
  }
}
