import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProductsVO, ProductsForm, ProductsQuery } from '@/api/product/products/types';
import { BaseQuery, BaseVO } from '@/api/product/base/types';

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

export const listProducts = (query?: ProductsQuery): AxiosPromise<BaseVO[]> => {
  return request({
    url: '/product/protocolProducts/list',
    method: 'get',
    params: query
  });
};


/**
* 获取协议的关联产品Id
* */
export const getProtocolProductIds = (protocolId: string | number): AxiosPromise<string[]> => {
  return request({
    url: '/product/protocolProducts/getProductIds/' + protocolId,
    method: 'get'
  });
}




/**
 * 查询协议产品关联详细
 * @param id
 */
export const getProducts = (id: string | number): AxiosPromise<ProductsVO> => {
  return request({
    url: '/product/protocolProducts/' + id,
    method: 'get'
  });
};

/**
 * 新增协议产品关联
 * @param data
 */
export const addProducts = (data: ProductsForm) => {
  return request({
    url: '/product/protocolProducts',
    method: 'post',
    data: data
  });
};

/**
 * 修改协议产品关联
 * @param data
 */
export const updateProducts = (data: ProductsForm) => {
  return request({
    url: '/product/protocolProducts',
    method: 'put',
    data: data
  });
};

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

/**
 * 修改协议产品价格
 * @param data
 */
export const updateProductsPrice = (data: ProductsForm) => {
  return request({
    url: '/product/protocolProducts/updateProtocolPrice',
    method: 'put',
    data: data
  })
}

/**
 * 批量审核协议商品
 * @param data 审核参数列表
 */
export const updateProductsAudit = (data: { id: string | number; auditStatus: number; auditReason: string }[]) => {
  return request({
    url: '/product/protocolProducts/batchAudit',
    method: 'post',
    data: data
  })
}
