import request from '@/utils/request'
import type { ApiResult, PageResult } from '@/api'
import type { ShopPointsProduct, ShopPointsProductParam } from './model'

/**
 * 分页查询积分兑换商品表
 */
export async function pageShopPointsProduct(params: ShopPointsProductParam) {
  const res = await request.get<ApiResult<PageResult<ShopPointsProduct>>>(
    '/shop/shop-points-product/page',
    params
  )
  if (res.code === 0) {
    return res.data
  }
  return Promise.reject(new Error(res.message))
}

/**
 * 查询积分兑换商品表列表
 */
export async function listShopPointsProduct(params?: ShopPointsProductParam) {
  const res = await request.get<ApiResult<ShopPointsProduct[]>>(
    '/shop/shop-points-product',
    params
  )
  if (res.code === 0 && res.data) {
    return res.data
  }
  return Promise.reject(new Error(res.message))
}

/**
 * 根据id查询积分兑换商品详情
 */
export async function getShopPointsProduct(id: number) {
  const res = await request.get<ApiResult<ShopPointsProduct>>(
    '/shop/shop-points-product/' + id
  )
  if (res.code === 0 && res.data) {
    return res.data
  }
  return Promise.reject(new Error(res.message))
}
