import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { ShopGoodsBrowse, ShopGoodsBrowseParam } from './model';

/**
 * 后台管理：分页查询浏览记录
 */
export async function pageShopGoodsBrowse(params: ShopGoodsBrowseParam) {
  const res = await request.get<ApiResult<PageResult<ShopGoodsBrowse>>>(
    '/shop/shop-goods-browse/admin/page',
    { params }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 后台管理：删除单条浏览记录
 */
export async function removeShopGoodsBrowse(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/shop/shop-goods-browse/admin/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
