import { apiClient } from '@/shared/api/client'

import type { ApiResponse, PaginatedResult } from '@/shared/types/types'

export interface NotificationItem {
  id: number
  user_id: number
  type: string
  title: string
  content: string
  biz_type: string
  biz_id?: number
  read_at?: string
  created_at: string
}

export async function fetchNotifications(page = 1, pageSize = 20) {
  const { data } = await apiClient.get<ApiResponse<PaginatedResult<NotificationItem>>>('/notifications', {
    params: { page, page_size: pageSize },
  })
  return data.data
}

export async function markNotificationRead(id: number) {
  const { data } = await apiClient.post<ApiResponse<{ read: boolean }>>(`/notifications/${id}/read`)
  return data.data
}
