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

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

export interface NotificationSearchParam {
  isRead?: boolean;
  refType?: string;
  pageNum?: number;
  pageSize?: number;
}

export interface MeSummary {
  userId: number;
  agentId?: number;
  statementCount: number;
  withdrawRequestCount: number;
  unreadNotificationCount: number;
}

export const notificationApi = {
  list: (params: NotificationSearchParam = {}) =>
    unwrap<PageResponse<NotificationResp>>(api.get('/api/mobile/me/notifications', { params })),
  markRead: (id: number) =>
    unwrap<void>(api.post(`/api/mobile/me/notifications/${id}/read`, {})),
  markAllRead: () =>
    unwrap<number>(api.post('/api/mobile/me/notifications/read-all', {})),
  summary: () => unwrap<MeSummary>(api.get('/api/mobile/me/summary')),
};
