import { apiRequest } from "./client";

export type NotificationItem = {
  id: number;
  type?: string;
  title?: string;
  content?: string;
  related_type?: string;
  relatedType?: string;
  related_id?: number;
  relatedId?: number;
  targetType?: string;
  targetId?: number;
  page_target?: string;
  pageTarget?: string;
  actionText?: string;
  read_at?: string | null;
  readAt?: string | null;
  isRead?: boolean;
  created_at?: string;
  createdAt?: string;
};

export function getNotifications() {
  return apiRequest("/api/notifications") as Promise<NotificationItem[]>;
}

export function markNotificationRead(id: number) {
  return apiRequest(`/api/notifications/${id}/read`, { method: "POST" });
}

export function markAllNotificationsRead() {
  return apiRequest("/api/notifications/read-all", { method: "POST" });
}
