import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PoolLinkVO, PoolLinkForm, PoolLinkQuery } from '@/api/product/poolLink/types';
export type { PoolLinkForm };

/**
 * 查询产品池和产品关联列表
 * @param query
 * @returns {*}
 */

export const listPoolLink = (query?: PoolLinkQuery): AxiosPromise<PoolLinkVO[]> => {
  return request({
    url: '/product/poolLink/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询产品池和产品关联详细
 * @param id
 */
export const getPoolLink = (id: string | number): AxiosPromise<PoolLinkVO> => {
  return request({
    url: '/product/poolLink/' + id,
    method: 'get'
  });
};

/**
 * 新增产品池和产品关联
 * @param data
 */
export const addPoolLink = (data: PoolLinkForm) => {
  return request({
    url: '/product/poolLink',
    method: 'post',
    data: data
  });
};

/**
 * 修改产品池和产品关联
 * @param data
 */
export const updatePoolLink = (data: PoolLinkForm) => {
  return request({
    url: '/product/poolLink',
    method: 'put',
    data: data
  });
};

/**
 * 删除产品池和产品关联
 * @param id
 */
export const delPoolLink = (id: string | number | Array<string | number>) => {
  return request({
    url: '/product/poolLink/' + id,
    method: 'delete'
  });
};

/**
 * 批量添加商品到商品池
 * @param data 批量添加参数
 */
export interface BatchAddProductData {
  poolId: string | number;
  products: Array<{
    productId: string | number;
    agreementPrice?: number;
  }>;
}

export const batchAddProducts = (data: BatchAddProductData) => {
  return request({
    url: '/product/poolLink/batchAdd',
    method: 'post',
    data: data
  });
};

/**
 * 批量审核商品进入商品池
 * @param data 审核参数列表
 */
export const batchReview = (data: PoolLinkForm[]) => {
  return request({
    url: '/product/poolLink/batchReview',
    method: 'post',
    data: data
  });
};

/**
 * 提交审核商品到商品池
 * @param data 提交审核参数列表
 */
export const reSubmit = (data: PoolLinkForm[]) => {
  return request({
    url: '/product/poolLink/reSubmit',
    method: 'post',
    data: data
  });
};

/**
 * 编辑商品价格
 * @param data 价格参数
 */
export const editPrice = (data: PoolLinkForm) => {
  return request({
    url: '/product/poolLink/editPrice',
    method: 'post',
    data: data
  });
};

/**
 * 编辑商品库存
 * @param data 库存参数
 */
export const editStock = (data: PoolLinkForm) => {
  return request({
    url: '/product/poolLink/editStock',
    method: 'post',
    data: data
  });
};

/**
 * 清空产品池
 * @param poolId 产品池ID
 */
export const clearPool = (poolId: string | number) => {
  return request({
    url: '/product/poolLink/clear/' + poolId,
    method: 'delete'
  });
};
