import request from '@/utils/request';

/**
 * 分页查询
 * @param params 查询条件
 */
export async function pageProductCoupon(params) {
  const res = await request.get('/car/productCoupon/page', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * @param data
 */
export async function addProductCoupon(data) {
  const res = await request.post('/car/productCoupon', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * @param data
 */
export async function updateProductCoupon(data) {
  const res = await request.put('/car/productCoupon', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function updateProductCouponStatus(id, status) {
  const res = await request.put('/car/productCoupon/status', {
    id,
    status
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除
 * @param ids id集合
 */
export async function removeProductCoupon(ids) {
  const res = await request.delete('/car/productCoupon/delete', {
    data: { ids }
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
