import { apiRequestData } from "./http"; export type NotificationItem = { id: string; type: string; title: string; body: string | null; targetType: string | null; targetId: string | null; readAt: string | null; createdAt: string; }; export type NotificationListResponse = { page: number; pageSize: number; total: number; unreadOnly: boolean; unreadCount: number; items: NotificationItem[]; }; export type NotificationListQuery = { page?: number; pageSize?: number; unreadOnly?: boolean; type?: string; }; function toQueryString(query: NotificationListQuery) { const params = new URLSearchParams(); if (query.page != null) params.set("page", String(query.page)); if (query.pageSize != null) params.set("pageSize", String(query.pageSize)); if (query.unreadOnly != null) params.set("unreadOnly", query.unreadOnly ? "1" : "0"); if (query.type) params.set("type", query.type); const qs = params.toString(); return qs ? `?${qs}` : ""; } export async function fetchNotifications(query: NotificationListQuery = {}) { return apiRequestData(`/api/notifications${toQueryString(query)}`); } export async function markNotificationRead(notificationId: string) { return apiRequestData<{ id: string; readAt: string | null }>( `/api/notifications/${notificationId}/mark-read`, { method: "POST", body: JSON.stringify({}), }, ); } export async function markAllNotificationsRead() { return apiRequestData<{ updatedCount: number }>("/api/notifications/mark-all-read", { method: "POST", body: JSON.stringify({}), }); }