import request from '@/utils/request'
import type { ApiResult, PageResult } from '@/api'
import type { UserPointLog, UserPointLogParam } from './model'
import { SERVER_API_URL } from '@/config/setting'

/**
 * 分页查询积分明细
 */
export async function pageUserPointLog(params: UserPointLogParam) {
  const res = await request.get<ApiResult<PageResult<UserPointLog>>>(
    SERVER_API_URL + '/sys/user-point-log/page',
    { params }
  )
  if (res.data.code === 0) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.message))
}

/**
 * 查询积分明细列表
 */
export async function listUserPointLog(params?: UserPointLogParam) {
  const res = await request.get<ApiResult<UserPointLog[]>>(
    SERVER_API_URL + '/sys/user-point-log',
    { params }
  )
  if (res.data.code === 0 && res.data.data) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.message))
}
