import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
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.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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

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

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

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

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