import request from '@/utils/http'

/**
 * 配额包管理 API
 */

/**
 * 获取配额包列表
 */
export function fetchQuotaPackageList(params?: {
  quotaType?: number
  isActive?: boolean
  page?: number
  pageSize?: number
}) {
  return request.get<Api.Common.PageResult<Api.QuotaPackage.QuotaPackageListDto>>({
    url: '/api/admin/v1/quota-packages',
    params
  })
}

/**
 * 创建配额包
 */
export function fetchCreateQuotaPackage(data: Api.QuotaPackage.CreateQuotaPackageCommand) {
  return request.post<Api.QuotaPackage.QuotaPackageDto>({
    url: '/api/admin/v1/quota-packages',
    data
  })
}

/**
 * 更新配额包
 */
export function fetchUpdateQuotaPackage(
  quotaPackageId: string,
  data: Api.QuotaPackage.UpdateQuotaPackageCommand
) {
  return request.put<Api.QuotaPackage.QuotaPackageDto>({
    url: `/api/admin/v1/quota-packages/${quotaPackageId}`,
    data
  })
}

/**
 * 删除配额包（软删）
 */
export function fetchDeleteQuotaPackage(quotaPackageId: string) {
  return request.del<boolean>({
    url: `/api/admin/v1/quota-packages/${quotaPackageId}`
  })
}

/**
 * 更新配额包状态（上架/下架）
 */
export function fetchUpdateQuotaPackageStatus(quotaPackageId: string, isActive: boolean) {
  return request.put<boolean>({
    url: `/api/admin/v1/quota-packages/${quotaPackageId}/status`,
    data: {
      isActive
    }
  })
}

/**
 * 为租户购买配额包
 */
export function fetchPurchaseQuotaPackage(
  tenantId: string,
  data: Api.QuotaPackage.PurchaseQuotaPackageCommand
) {
  return request.post<Api.QuotaPackage.TenantQuotaPurchaseDto>({
    url: `/api/admin/v1/tenants/${tenantId}/quota-packages`,
    data
  })
}

/**
 * 获取租户配额使用情况
 */
export function fetchTenantQuotaUsage(tenantId: string, params?: { quotaType?: number }) {
  return request.get<Api.QuotaPackage.TenantQuotaUsageDto[]>({
    url: `/api/admin/v1/tenants/${tenantId}/quota-usage`,
    params
  })
}

/**
 * 获取租户配额购买记录
 */
export function fetchTenantQuotaPurchases(
  tenantId: string,
  params?: { page?: number; pageSize?: number }
) {
  return request.get<Api.Common.PageResult<Api.QuotaPackage.TenantQuotaPurchaseDto>>({
    url: `/api/admin/v1/tenants/${tenantId}/quota-purchases`,
    params
  })
}
