// The durable, server-backed notification inbox (distinct from the client-side transient
// toast/bell, which lives only in localStorage). Only touches core's req.
import { req } from "./core";

// A durable, server-backed notification (the inbox center). Distinct from the client-side
// transient toast/bell, which lives only in localStorage.
export interface AppNotification {
  id: number;
  type: string;
  title: string;
  body: string | null;
  data: Record<string, unknown> | null;
  read: boolean;
  dismissed: boolean;
  created_at: string | null;
}

export const notificationsApi = {
  notifications: (includeDismissed = false): Promise<{ items: AppNotification[]; total: number }> =>
    req(`/api/me/notifications?include_dismissed=${includeDismissed}`),
  notificationUnreadCount: (): Promise<{ count: number }> =>
    req("/api/me/notifications/unread_count"),
  markNotificationRead: (id: number) => req(`/api/me/notifications/${id}/read`, { method: "POST" }),
  markAllNotificationsRead: () => req("/api/me/notifications/read_all", { method: "POST" }),
  dismissNotification: (id: number) =>
    req(`/api/me/notifications/${id}/dismiss`, { method: "POST" }),
  clearNotifications: () => req("/api/me/notifications/clear", { method: "POST" }),
};
