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

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

export interface WalletAccount {
  user_id: number
  available_balance_cent: number
  frozen_balance_cent: number
  status: WalletStatus
}

export interface WalletLedger {
  id: number
  ledger_no: string
  user_id: number
  order_id?: number
  direction: LedgerDirection
  amount_cent: number
  balance_after_cent: number
  balance_type: BalanceType
  biz_type: string
  biz_no: string
  remark: string
  created_at: string
}

export async function fetchWalletBalance() {
  const { data } = await apiClient.get<ApiResponse<WalletAccount>>('/wallet/balance')
  return data.data
}

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