import type { NotificationItem } from './dto/notification'
import { extractItems } from '~/utils/api'

export const listUnreadNotifications = async () => {
  const api = useApi()
  const data = await api.get<NotificationItem[] | { 'hydra:member'?: NotificationItem[] }>(
    '/notifications/unread',
    {},
    { toast: false }
  )

  return extractItems<NotificationItem>(data)
}

export const listTodayNotifications = async () => {
  const api = useApi()
  const data = await api.get<NotificationItem[] | { 'hydra:member'?: NotificationItem[] }>(
    '/notifications/today',
    {},
    { toast: false }
  )

  return extractItems<NotificationItem>(data)
}

export const listHistoryNotifications = async () => {
  const api = useApi()
  const data = await api.get<NotificationItem[] | { 'hydra:member'?: NotificationItem[] }>(
    '/notifications/history',
    {},
    { toast: false }
  )

  return extractItems<NotificationItem>(data)
}

export const markAllNotificationsRead = async () => {
  const api = useApi()
  return api.post('/notifications/mark-all-read', {}, { toast: false })
}
