import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 钱包交易记录信息 */
export interface WalletTransaction {
          id: number; // 主键 Id
          userId: number; // 用户 Id
          orderId: number; // 订单 Id
          amount?: number; // 金额
          type?: number; // 变动类型
          beforeBalance?: number; // 变动前余额
          afterBalance?: number; // 变动后余额
          description: string; // 描述
          createdAt?: string | Dayjs; // 创建时间
}

/** 用户钱包信息 */
export interface UserWallet {
          id: number; // 主键 Id
          userId?: number; // 用户 id
          balance?: number; // 余额
          version?: number; // 乐观锁版本
          status?: number; // 状态
          createdAt?: string | Dayjs; // 创建时间
          updatedAt?: string | Dayjs; // 更新时间
  }

// 用户钱包 API
export const UserWalletApi = {
  // 查询用户钱包分页
  getUserWalletPage: async (params: any) => {
    return await request.get({ url: `/keyboard/user-wallet/page`, params })
  },

  // 查询用户钱包详情
  getUserWallet: async (id: number) => {
    return await request.get({ url: `/keyboard/user-wallet/get?id=` + id })
  },

  // 新增用户钱包
  createUserWallet: async (data: UserWallet) => {
    return await request.post({ url: `/keyboard/user-wallet/create`, data })
  },

  // 修改用户钱包
  updateUserWallet: async (data: UserWallet) => {
    return await request.put({ url: `/keyboard/user-wallet/update`, data })
  },

  // 删除用户钱包
  deleteUserWallet: async (id: number) => {
    return await request.delete({ url: `/keyboard/user-wallet/delete?id=` + id })
  },

  /** 批量删除用户钱包 */
  deleteUserWalletList: async (ids: number[]) => {
    return await request.delete({ url: `/keyboard/user-wallet/delete-list?ids=${ids.join(',')}` })
  },

  // 导出用户钱包 Excel
  exportUserWallet: async (params) => {
    return await request.download({ url: `/keyboard/user-wallet/export-excel`, params })
  },

// ==================== 子表（钱包交易记录） ====================

  // 获得钱包交易记录分页
  getWalletTransactionPage: async (params) => {
    return await request.get({ url: `/keyboard/user-wallet/wallet-transaction/page`, params })
  },
  // 新增钱包交易记录
  createWalletTransaction: async (data: WalletTransaction) => {
    return await request.post({ url: `/keyboard/user-wallet/wallet-transaction/create`, data })
  },

  // 修改钱包交易记录
  updateWalletTransaction: async (data: WalletTransaction) => {
    return await request.put({ url: `/keyboard/user-wallet/wallet-transaction/update`, data })
  },

  // 删除钱包交易记录
  deleteWalletTransaction: async (id: number) => {
    return await request.delete({ url: `/keyboard/user-wallet/wallet-transaction/delete?id=` + id })
  },

  /** 批量删除钱包交易记录 */
  deleteWalletTransactionList: async (ids: number[]) => {
    return await request.delete({ url: `/keyboard/user-wallet/wallet-transaction/delete-list?ids=${ids.join(',')}` })
  },

  // 获得钱包交易记录
  getWalletTransaction: async (id: number) => {
    return await request.get({ url: `/keyboard/user-wallet/wallet-transaction/get?id=` + id })
  }
}