import api, { PageResponse, unwrap } from './request';

export interface UserNotificationRow extends Record<string, unknown> {
  notificationId: number;
  userId: number;
  title: string;
  content: string;
  notificationType: string;
  refType?: string;
  refId?: number;
  isRead: boolean;
  readAt?: string;
  createdAt: string;
}

export const notificationApi = {
  list: (p?: { isRead?: boolean; pageNum?: number; pageSize?: number }) =>
    unwrap<PageResponse<UserNotificationRow>>(
      api.get('/api/user-notifications', { params: p }),
    ),
  unreadCount: () =>
    unwrap<number>(api.get('/api/user-notifications/unread-count')),
  markRead: (id: number) =>
    unwrap<void>(api.post(`/api/user-notifications/${id}/read`)),
  markAllRead: () =>
    unwrap<void>(api.post('/api/user-notifications/read-all')),
};
