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

export type AdminReview = {
  id: string
  rating: number
  text: string | null
  status: string
  createdAt: string
  moderatedAt: string | null
  user: { id: string; email: string; name: string | null }
  product: { id: string; title: string }
}

export type AdminReviewsListResponse = {
  items: AdminReview[]
  total: number
  page: number
  pageSize: number
}

export async function fetchAdminReviews(params?: {
  status?: string
  page?: number
  pageSize?: number
}): Promise<AdminReviewsListResponse> {
  const { data } = await apiClient.get<AdminReviewsListResponse>('admin/reviews', { params })
  return data
}

export async function moderateReview(id: string, action: 'approve' | 'reject'): Promise<void> {
  await apiClient.patch(`admin/reviews/${id}`, { action })
}
