import axios from 'src/utils/axios';

export async function getNotifications(params) {
  const res = await axios.get('/notifications/', { params });
  const {data} = res;
  if (Array.isArray(data)) return { results: data, count: data.length };
  return { results: data?.results ?? [], count: data?.count ?? 0 };
}

export async function getUnreadNotifications() {
  const res = await axios.get('/notifications/unread/');
  const data = res.data ?? {};
  return {
    data: data.data ?? [],
    count: data.count ?? 0,
  };
}

export async function markAsRead(id) {
  await axios.post(`/notifications/${id}/mark_as_read/`);
}

export async function markAllAsRead() {
  await axios.post('/notifications/mark_all_as_read/');
}

export async function deleteNotification(id) {
  await axios.delete(`/notifications/${id}/`);
}
