import request from '@/utils/request';

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

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

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

export async function updateProductStatus(id, status) {
  const res = await request.put('/car/product/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 removeProduct(ids) {
  const res = await request.delete('/car/product/delete', {
    data: { ids }
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * @param id 产品id
 */
export async function getProduct(id) {
  const res = await request.get('/car/product/' + id);
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * @param params
 * @returns {Promise<*>}
 */
export async function getCouponBizList(params) {
  const res = await request.get('/car/product/couponBizList', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
