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

import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
import type { RealnameStatusValue, RiskStatus, UserStatus } from '@/shared/types/status'

export interface AdminUserItem {
  id: number
  phone: string
  nickname: string
  realname_status: RealnameStatusValue
  risk_status: RiskStatus
  credit_score: number
  status: UserStatus
  order_count: number
  listing_count: number
  dispute_count: number
  last_login_at?: string
  created_at: string
  updated_at: string
}

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

export async function freezeAdminUser(id: number, reason: string) {
  const { data } = await apiClient.post<ApiResponse<AdminUserItem>>(`/admin/users/${id}/freeze`, { reason })
  return data.data
}

export async function unfreezeAdminUser(id: number) {
  const { data } = await apiClient.post<ApiResponse<AdminUserItem>>(`/admin/users/${id}/unfreeze`)
  return data.data
}
