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

/** 租户内购分成记录信息 */
export interface TenantCommission {
          id: number; // 主键
          purchaseRecordId?: number; // 内购记录ID
          transactionId: string; // 内购交易ID
          inviteeUserId: number; // 被邀请用户ID（购买用户）
          inviterUserId: number; // 邀请人用户ID
          purchaseAmount: number; // 内购金额
          commissionRate: number; // 分成比例
          commissionAmount: number; // 分成金额
          status: string; // 状态：PENDING-待结算，SETTLED-已结算，REFUNDED-已退款
          purchaseTime: string | Dayjs; // 内购时间
          settledAt: string | Dayjs; // 结算时间
          balanceTransactionId: number; // 关联的余额交易记录ID
          createdAt: string | Dayjs; // 创建时间
          updatedAt: string | Dayjs; // 更新时间
          remark: string; // 备注
  }

// 租户内购分成记录 API
export const TenantCommissionApi = {
  // 查询租户内购分成记录分页
  getTenantCommissionPage: async (params: any) => {
    return await request.get({ url: `/keyboard/tenant-commission/page`, params })
  },
  // 查询本人租户内购分成记录分页
  getMyPage: async (params: any) => {
    return await request.get({ url: `/keyboard/tenant-commission/my-page`, params })
  },
  // 查询租户内购分成记录详情
  getTenantCommission: async (id: number) => {
    return await request.get({ url: `/keyboard/tenant-commission/get?id=` + id })
  },

  // 新增租户内购分成记录
  createTenantCommission: async (data: TenantCommission) => {
    return await request.post({ url: `/keyboard/tenant-commission/create`, data })
  },

  // 修改租户内购分成记录
  updateTenantCommission: async (data: TenantCommission) => {
    return await request.put({ url: `/keyboard/tenant-commission/update`, data })
  },

  // 删除租户内购分成记录
  deleteTenantCommission: async (id: number) => {
    return await request.delete({ url: `/keyboard/tenant-commission/delete?id=` + id })
  },

  /** 批量删除租户内购分成记录 */
  deleteTenantCommissionList: async (ids: number[]) => {
    return await request.delete({ url: `/keyboard/tenant-commission/delete-list?ids=${ids.join(',')}` })
  },

  // 导出租户内购分成记录 Excel
  exportTenantCommission: async (params) => {
    return await request.download({ url: `/keyboard/tenant-commission/export-excel`, params })
  }
}