import request from '@/config/axios'

// 租户余额 VO
export interface TenantBalanceVO {
  id: number // 租户 Id
  balance: number // 当前积分余额
  version: number // 乐观锁版本号
  updatedAt: Date // 更新时间
}

// 租户余额 API
export const TenantBalanceApi = {
  // 查询租户余额分页
  getTenantBalancePage: async (params: any) => {
    return await request.get({ url: `/system/tenant-balance/page`, params })
  },
  // 查询下级租户余额分页
  getSubordinateaMountPage: async (params: any) => {
    return await request.get({ url: `/system/tenant-balance/get-self-subordinate-amount-page`, params })
  },

   //查看当前余额
   getselfamount: async () => {
    return await request.get({ url: `/system/tenant-balance/get-self-amount` })
  },
  
  // 查询租户余额详情
  getTenantBalance: async (id: number) => {
    return await request.get({ url: `/system/tenant-balance/get?id=` + id })
  },

  // 新增租户余额
  createTenantBalance: async (data: TenantBalanceVO) => {
    return await request.post({ url: `/system/tenant-balance/create`, data })
  },

  // 修改租户余额
  updateTenantBalance: async (data: TenantBalanceVO) => {
    return await request.put({ url: `/system/tenant-balance/update`, data })
  },

  // 删除租户余额
  deleteTenantBalance: async (id: number) => {
    return await request.delete({ url: `/system/tenant-balance/delete?id=` + id })
  },
  // 转账租户余额
  tenantTransfer: async (data: TenantBalanceVO) => {
    return await request.post({ url: `/system/tenant-balance/transfer`, data })
  },
  addAmount: async (data: TenantBalanceVO) => {
    return await request.post({ url: `/system/tenant-balance/addAmount`, data })
  },
  // 导出租户余额 Excel
  exportTenantBalance: async (params) => {
    return await request.download({ url: `/system/tenant-balance/export-excel`, params })
  },

// ==================== 子表（租户余额） ====================

  // 获得租户余额分页
  getTenantPointsPage: async (params) => {
    return await request.get({ url: `/system/tenant-points/transaction-history/page`, params })
  },
  // 新增租户余额
  createTenantPoints: async (data) => {
    return await request.post({ url: `/system/tenant-balance/tenant-points/create`, data })
  },

  // 修改租户余额
  updateTenantPoints: async (data) => {
    return await request.put({ url: `/system/tenant-balance/tenant-points/update`, data })
  },

  // 删除租户余额
  deleteTenantPoints: async (id: number) => {
    return await request.delete({ url: `/system/tenant-balance/tenant-points/delete?id=` + id })
  },

  // 获得租户余额
  getTenantPoints: async (id: number) => {
    return await request.get({ url: `/system/tenant-balance/tenant-points/get?id=` + id })
  }
}