import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { BaseVO, BaseForm, BaseQuery, StatusCountVo } from '@/api/product/base/types';
import { ContracproductVO, ContracproductForm, ContracproductQuery } from '@/api/product/contracproduct/types';

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

export const listContracproduct = (query?: ContracproductQuery): AxiosPromise<ContracproductVO[]> => {
  return request({
    url: '/product/contracproduct/list',
    method: 'get',
    params: query
  });
};

export const scmListContracproduct = (query?: ContracproductQuery): AxiosPromise<ContracproductVO[]> => {
  return request({
    url: '/product/contracproduct/scm/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询合同产品关联详细
 * @param id
 */
export const getContracproduct = (id: string | number): AxiosPromise<ContracproductVO> => {
  return request({
    url: '/product/contracproduct/' + id,
    method: 'get'
  });
};

/**
 * 新增合同产品关联
 * @param data
 */
export const addContracproduct = (data: ContracproductForm) => {
  return request({
    url: '/product/contracproduct',
    method: 'post',
    data: data
  });
};

/**
 * 修改合同产品关联
 * @param data
 */
export const updateContracproduct = (data: ContracproductForm) => {
  return request({
    url: '/product/contracproduct',
    method: 'put',
    data: data
  });
};

/**
 * 删除合同产品关联
 * @param id
 */
export const delContracproduct = (id: string | number | Array<string | number>) => {
  return request({
    url: '/product/contracproduct/' + id,
    method: 'delete'
  });
};
/**
 * 查询产品基础信息列表
 * @param query
 * @returns {*}
 */

export const getContractProductList = (query?: BaseQuery): AxiosPromise<BaseVO[]> => {
  return request({
    url: '/product/contracproduct/getContractProductList',
    method: 'get',
    params: query
  });
};

/**
 * 删除合同产品关联
 * @param id
 */
export const delContracproductBySupplier = (productId: string | number, supplierId: string | number) => {
  return request({
    url: '/product/contracproduct/delContracproductBySupplier',
    params: { productId: productId, supplierId: supplierId },
    method: 'delete'
  });
};

/**
 * 下载导入模板
 */
export const importTemplate = () => {
  return request({
    url: '/product/contracproduct/importTemplate',
    method: 'post',
    responseType: 'blob'
  });
};

/**
 * 导入合同产品数据
 * @param file 导入文件
 */
export const importData = (file: File) => {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/product/contracproduct/importData',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};
