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

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

export interface AdminWalletLedger {
  id: number
  ledger_no: string
  user_id: number
  user_phone: string
  user_nickname: string
  order_id?: number
  order_no: string
  direction: LedgerDirection
  amount: number
  balance_after: number
  balance_type: BalanceType
  biz_type: string
  biz_no: string
  remark: string
  created_at: string
}

export interface AdminWalletLedgerQuery {
  user_id?: string
  order_id?: string
  biz_type?: string
  page?: number
  page_size?: number
}

export async function fetchAdminWalletLedger(query: AdminWalletLedgerQuery = {}) {
  const params = Object.fromEntries(Object.entries(query).filter(([, value]) => value !== '' && value !== undefined))
  const { data } = await apiClient.get<ApiResponse<PaginatedResult<AdminWalletLedger>>>('/admin/wallet/ledger', { params })
  return data.data
}
