import request from '@/utils/http'

/**
 * 玩家钱包流水 API接口
 */
export default {
  /**
   * 获取数据列表
   * @param params 搜索参数
   * @returns 数据列表
   */
  list(params: Record<string, any>) {
    return request.get<Api.Common.ApiPage & { total_coin_change?: number }>({
      url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/index',
      params
    })
  },

  /**
   * 读取数据
   * @param id 数据ID
   * @returns 数据详情
   */
  read(id: number | string) {
    return request.get<Api.Common.ApiData>({
      url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/read?id=' + id
    })
  },

  /**
   * 创建数据
   * @param params 数据参数
   * @returns 执行结果
   */
  save(params: Record<string, any>) {
    return request.post<any>({
      url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/save',
      data: params
    })
  },

  /**
   * 删除数据
   * @param id 数据ID
   * @returns 执行结果
   */
  delete(params: Record<string, any>) {
    return request.del<any>({
      url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/destroy',
      data: params
    })
  },

  /**
   * 获取玩家选项（id、username）用于下拉
   */
  getPlayerOptions(params?: Record<string, unknown>) {
    return request.get<{ id: number; username: string }[]>({
      url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions',
      params
    })
  },

  /**
   * 获取指定玩家当前平台币（钱包操作前）
   */
  getPlayerWalletBefore(playerId: number | string) {
    return request.get<{ wallet_before: number }>({
      url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerWalletBefore',
      params: { player_id: playerId }
    })
  },

  /**
   * 管理员钱包操作（加点/扣点）：更新玩家平台币并创建流水记录
   * type 3=加点 4=扣点
   */
  adminOperate(params: {
    player_id: number
    type: 3 | 4
    coin: number
    remark?: string
  }) {
    return request.post<any>({
      url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/adminOperate',
      data: params
    })
  }
}
