import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProductVO, ProductForm,ThirdProductVO, ProductQuery } from '@/api/external/product/types';

/**
 * 查询对外部推送商品列表
 * @param query
 * @returns {*}
 */

export const listProduct = (query?: ProductQuery): AxiosPromise<ProductVO[]> => {
  return request({
    url: '/external/product/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询对外部推送商品详细
 * @param id
 */
export const getProduct = (id: string | number): AxiosPromise<ProductVO> => {
  return request({
    url: '/external/product/' + id,
    method: 'get'
  });
};

/**
 * 新增对外部推送商品
 * @param data
 */
export const addProduct = (data: ProductForm) => {
  return request({
    url: '/external/product',
    method: 'post',
    data: data
  });
};

/**
 * 修改对外部推送商品
 * @param data
 */
export const updateProduct = (data: ProductForm) => {
  return request({
    url: '/external/product',
    method: 'put',
    data: data
  });
};

/**
 * 删除对外部推送商品
 * @param id
 */
export const delProduct = (id: string | number | Array<string | number>) => {
  return request({
    url: '/external/product/' + id,
    method: 'delete'
  });
};

/**
 * 获取第三方商品列表
 * @param query
 * @returns {*}
 */
export const getThirdProductPage = (query?: ProductQuery): AxiosPromise<ThirdProductVO[]> => {
  return request({
    url: '/external/product/getThirdProductPage',
    method: 'get',
    params: query
  });
};

/**
 * 根据商品ID查询对接信息
 * @param productId
 */
export const getProductByProductId = (productId: string | number): AxiosPromise<ProductVO> => {
  return request({
    url: '/external/product/getByProductId/' + productId,
    method: 'get'
  });
};

/**
 * 批量推送商品
 * @param ids
 */
export const batchPushProduct = (ids: string | number | Array<string | number>) => {
  return request({
    url: `/external/product/batchPush/${ids}`,
    method: 'post'
  });
};

/**
 * 商品上下架 状态变更
 * @param data 审核信息（包含id、productStatus、shelfComments）
 */
export const shelfReview = (data: ProductForm) => {
  return request({
    url: '/external/product/shelfReview',
    method: 'post',
    data: data
  });
};

export const batchInsertExternalProduct = (itemId: string | number, boList: any[]): AxiosPromise<any> => {
  return request({
    url: '/external/product/batch/insert',
    method: 'post',
    params: { itemId },
    data: boList
  });
};

/**
 * 获取项目已关联的商品ID列表
 * @param itemId
 */
export const getProjectProductIds = (itemId: string | number): AxiosPromise<(string | number)[]> => {
  return request({
    url: '/external/product/getProjectProductIds/' + itemId,
    method: 'get'
  });
};

/**
 * 删除项目关联商品
 * @param id
 */
export const delProjectProduct = (id: string | number | Array<string | number>) => {
  return request({
    url: '/external/product/project/' + id,
    method: 'delete'
  });
};

/**
 * 批量审核项目商品
 * @param data
 */
export const updateProjectProductAudit = (data: any[]) => {
  return request({
    url: '/external/product/batchReview',
    method: 'post',
    data: data
  });
};

/**
 * 批量更新第三方价格
 * @param data
 */
export const updateThirdPrice = (data: any[]) => {
  return request({
    url: '/external/product/updateProductPrice',
    method: 'post',
    data: data
  });
};
