import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PoolAuditVO, PoolAuditForm, PoolAuditQuery, ProductListVO } from '@/api/product/poolAudit/types';
import { BaseVO, BaseQuery } from '@/api/product/base/types';

/**
 * 查询产品池审核列表
 * @param query
 * @returns {*}
 */

export const listPoolAudit = (query?: PoolAuditQuery): AxiosPromise<PoolAuditVO[]> => {
  return request({
    url: '/product/poolAudit/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询产品池审核详细
 * @param id
 */
export const getPoolAudit = (id: string | number): AxiosPromise<PoolAuditVO> => {
  return request({
    url: '/product/poolAudit/' + id,
    method: 'get'
  });
};

/**
 * 新增产品池审核
 * @param data
 */
export const addPoolAudit = (data: PoolAuditForm) => {
  return request({
    url: '/product/poolAudit',
    method: 'post',
    data: data
  });
};

/**
 * 修改产品池审核
 * @param data
 */
export const updatePoolAudit = (data: PoolAuditForm) => {
  return request({
    url: '/product/poolAudit',
    method: 'put',
    data: data
  });
};

/**
 * 删除产品池审核
 * @param id
 */
export const delPoolAudit = (id: string | number | Array<string | number>) => {
  return request({
    url: '/product/poolAudit/' + id,
    method: 'delete'
  });
};

/**
 * 获取审核池里的商品列表
 * @param query
 * @returns {*}
 * */
export const getPoolAuditProductPage = (query?: BaseQuery & PageQuery): AxiosPromise<BaseVO[]> => {
  return request({
    url: '/product/poolAudit/getPoolAuditProductPage',
    method: 'get',
    params: query
  });
};

/**
 * 获取审核池里的商品列表
 * @param query
 * @returns {*}
 * */
export const selectPoolAuditProductPage = (query?: (BaseQuery & PageQuery) & { type?: number }): AxiosPromise<ProductListVO[]> => {
  return request({
    url: '/product/poolAudit/selectPoolAuditProductPage',
    method: 'get',
    params: query
  });
};

/**
 * 批量审核产品池商品
 * @param data
 */
export interface PoolAuditBatchData {
  poolAuditId: string | number;
  productIds: Array<string | number>;
  auditStatus: string | number;
  reason?: string;
}

export const batchAudit = (data: PoolAuditBatchData) => {
  return request({
    url: '/product/poolAudit/batchAudit',
    method: 'post',
    data: data
  });
};

/**
 * 申请入池单（待提交 -> 待审核）
 * @param id
 */
export const applyPoolAudit = (id: string | number) => {
  return request({
    url: '/product/poolAudit/apply/' + id,
    method: 'put'
  });
};

/**
 * 清空审核池
 * @param id
 */
export const clearPool = (id: string | number) => {
  return request({
    url: '/product/poolAudit/clearPool/' + id,
    method: 'delete'
  });
};

/**
 * 单条商品审核池
 * @param id
 */
export const audit = (data: PoolAuditBatchData) => {
  return request({
    url: '/product/poolAudit/audit',
    method: 'post',
    data: data
  });
};


