import { apiGet, apiPost } from "@/lib/api/client";

export type CafeNotification = {
  id: string;
  type: string;
  title: string;
  body?: string | null;
  referenceId?: string | null;
  tableNumber?: string | null;
  isRead: boolean;
  createdAt: string;
};

export type NotificationList = {
  items: CafeNotification[];
  unreadCount: number;
};

export async function fetchNotifications(
  cafeId: string,
  unreadOnly = false
): Promise<NotificationList> {
  return apiGet<NotificationList>(
    `/api/cafes/${cafeId}/notifications?unreadOnly=${unreadOnly}&limit=50`
  );
}

export async function fetchUnreadCount(cafeId: string): Promise<number> {
  const data = await apiGet<{ count: number }>(
    `/api/cafes/${cafeId}/notifications/unread-count`
  );
  return data.count;
}

export async function markNotificationsRead(
  cafeId: string,
  body: { ids?: string[]; all?: boolean }
): Promise<void> {
  await apiPost(`/api/cafes/${cafeId}/notifications/read`, body);
}
