import api from "./api.js";
import { unwrapData } from "./http.js";

export async function listHandoverNotifications() {
  const res = await api.get("/notifications/handover");
  const payload = unwrapData(res) ?? res?.data ?? {};
  return {
    items: Array.isArray(payload.data) ? payload.data : Array.isArray(payload) ? payload : [],
    unreadCount: Number(payload.unread_count) || 0
  };
}

export async function markHandoverNotificationRead(notificationId) {
  const res = await api.patch(`/notifications/handover/${notificationId}/read`);
  return unwrapData(res);
}

export async function markAllHandoverNotificationsRead() {
  const res = await api.patch("/notifications/handover/read-all");
  return unwrapData(res);
}
