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

/** 租户积分记录信息 */
export interface TenantBalanceTransaction {
          id: number; // 主键
          points?: number; // 本次变动点数，正加负减
          balance: number; // 变动后余额快照（冗余）
          type: string; // 变动类型，如 TRANSFER_IN, WITHDRAW，REFUND_COMMISSION ，RECHARGE_COMMISSION
          description: string; // 变动描述
          orderId: string; // 订单 Id/业务单号
          bizNo: string; // 业务流水号（转账、订单等唯一标识）
          operatorId: number; // 操作人 Id
          createdAt?: string | Dayjs; // 创建时间
          remark: string; // 备注
}

/** 租户余额信息 */
export interface TenantBalance {
          id: number; // 租户 Id
          balance?: number; // 当前积分余额
          version?: number; // 乐观锁版本号
          updatedAt?: string | Dayjs; // 更新时间
          testAccountNum: number; // 测试账户数量
  }

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

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

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

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

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

  /** 批量删除租户余额 */
  deleteTenantBalanceList: async (ids: number[]) => {
    return await request.delete({ url: `/keyboard/tenant-balance/delete-list?ids=${ids.join(',')}` })
  },

  // 导出租户余额 Excel
  exportTenantBalance: async (params) => {
    return await request.download({ url: `/keyboard/tenant-balance/export-excel`, params })
  },

// ==================== 子表（租户积分记录） ====================

  // 获得租户积分记录分页
  getTenantBalanceTransactionPage: async (params) => {
    return await request.get({ url: `/keyboard/tenant-balance/tenant-balance-transaction/page`, params })
  },
  // 新增租户积分记录
  createTenantBalanceTransaction: async (data: TenantBalanceTransaction) => {
    return await request.post({ url: `/keyboard/tenant-balance/tenant-balance-transaction/create`, data })
  },

  // 修改租户积分记录
  updateTenantBalanceTransaction: async (data: TenantBalanceTransaction) => {
    return await request.put({ url: `/keyboard/tenant-balance/tenant-balance-transaction/update`, data })
  },

  // 删除租户积分记录
  deleteTenantBalanceTransaction: async (id: number) => {
    return await request.delete({ url: `/keyboard/tenant-balance/tenant-balance-transaction/delete?id=` + id })
  },

  /** 批量删除租户积分记录 */
  deleteTenantBalanceTransactionList: async (ids: number[]) => {
    return await request.delete({ url: `/keyboard/tenant-balance/tenant-balance-transaction/delete-list?ids=${ids.join(',')}` })
  },
   /** 充值租户积分记录 */
   addAmountBalance: async (data: TenantBalance) => {
    return await request.post({ url: `/keyboard/tenant-balance/addAmount`,data })
  },
  
  // 获得租户积分记录
  getTenantBalanceTransaction: async (id: number) => {
    return await request.get({ url: `/keyboard/tenant-balance/tenant-balance-transaction/get?id=` + id })
  }
}