import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api/index';
import type { ShopStoreFence, ShopStoreFenceParam } from './model';

/**
 * 分页查询黄家明_电子围栏
 */
export async function pageShopStoreFence(params: ShopStoreFenceParam) {
  const res = await request.get<ApiResult<PageResult<ShopStoreFence>>>(
    '/shop/shop-store-fence/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询黄家明_电子围栏列表
 */
export async function listShopStoreFence(params?: ShopStoreFenceParam) {
  const res = await request.get<ApiResult<ShopStoreFence[]>>(
    '/shop/shop-store-fence',
    params
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加黄家明_电子围栏
 */
export async function addShopStoreFence(data: ShopStoreFence) {
  const res = await request.post<ApiResult<unknown>>(
    '/shop/shop-store-fence',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改黄家明_电子围栏
 */
export async function updateShopStoreFence(data: ShopStoreFence) {
  const res = await request.put<ApiResult<unknown>>(
    '/shop/shop-store-fence',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除黄家明_电子围栏
 */
export async function removeShopStoreFence(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/shop/shop-store-fence/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除黄家明_电子围栏
 */
export async function removeBatchShopStoreFence(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/shop/shop-store-fence/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询黄家明_电子围栏
 */
export async function getShopStoreFence(id: number) {
  const res = await request.get<ApiResult<ShopStoreFence>>(
    '/shop/shop-store-fence/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
