import { get, put } from '../utils/request';

export interface MessageItem {
  id: string;
  title: string;
  content: string;
  type: string; // 'transaction' | 'expiry' | 'price' | 'announcement'
  isRead: boolean;
  createdAt: string;
}

export interface PaginatedMessages {
  items: MessageItem[];
  total: number;
}

/** 获取消息列表 */
export function getMessages(params?: { type?: string; page?: number; limit?: number }) {
  return get<PaginatedMessages>('/api/v1/notifications', {
    type: params?.type,
    page: params?.page ?? 1,
    limit: params?.limit ?? 50,
  });
}

/** 获取未读数 */
export function getUnreadCount() {
  return get<{ count: number }>('/api/v1/notifications/unread-count');
}

/** 标记已读 */
export function markAsRead(notificationId: string) {
  return put<void>(`/api/v1/notifications/${notificationId}/read`);
}

/** 全部标记已读 */
export function markAllRead() {
  return put<void>('/api/v1/notifications/read-all');
}
