import api from './api'
import type {
  Notification,
  NotificationPreferences,
  NotificationStats,
  NotificationType
} from '@/types/notification'

export async function getNotifications(
  skip = 0,
  limit = 50,
  unreadOnly = false,
  typeFilter?: NotificationType
): Promise<Notification[]> {
  const params: any = { skip, limit, unread_only: unreadOnly }
  if (typeFilter) {
    params.type_filter = typeFilter
  }
  
  const response = await api.get('/notifications', { params })
  return response.data
}

export async function getNotificationStats(): Promise<NotificationStats> {
  const response = await api.get('/notifications/stats')
  return response.data
}

export async function markNotificationsRead(notificationIds: number[]): Promise<void> {
  await api.post('/notifications/mark-read', { notification_ids: notificationIds })
}

export async function markAllNotificationsRead(): Promise<void> {
  await api.post('/notifications/mark-all-read')
}

export async function deleteNotification(notificationId: number): Promise<void> {
  await api.delete(`/notifications/${notificationId}`)
}

export async function getNotificationPreferences(): Promise<NotificationPreferences> {
  const response = await api.get('/notifications/preferences')
  return response.data
}

export async function updateNotificationPreferences(
  data: Partial<NotificationPreferences>
): Promise<NotificationPreferences> {
  const response = await api.put('/notifications/preferences', data)
  return response.data
}
