import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { QcInspectionItemVO, QcInspectionItemForm, QcInspectionItemQuery } from '@/api/qms/qcInspectionItem/types';

/**
 * 查询检测项定义列表
 * @param query
 * @returns {*}
 */

export const listQcInspectionItem = (query?: QcInspectionItemQuery): AxiosPromise<QcInspectionItemVO[]> => {
  return request({
    url: '/qms/qcInspectionItem/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询检测项定义详细
 * @param itemId
 */
export const getQcInspectionItem = (itemId: string | number): AxiosPromise<QcInspectionItemVO> => {
  return request({
    url: '/qms/qcInspectionItem/' + itemId,
    method: 'get'
  });
};

/**
 * 新增检测项定义
 * @param data
 */
export const addQcInspectionItem = (data: QcInspectionItemForm) => {
  return request({
    url: '/qms/qcInspectionItem',
    method: 'post',
    data: data
  });
};

/**
 * 修改检测项定义
 * @param data
 */
export const updateQcInspectionItem = (data: QcInspectionItemForm) => {
  return request({
    url: '/qms/qcInspectionItem',
    method: 'put',
    data: data
  });
};

/**
 * 删除检测项定义
 * @param itemId
 */
export const delQcInspectionItem = (itemId: string | number | Array<string | number>) => {
  return request({
    url: '/qms/qcInspectionItem/' + itemId,
    method: 'delete'
  });
};


/**
 * 下拉框查询检测项定义列表
 * @param query
 * @returns {*}
 */
export function getQcInspectionItemList (query) {
    return request({
        url: '/qms/qcInspectionItem/getQcInspectionItemList',
        method: 'get',
        params: query
    });
};

/**
 * 导入数据
 *
 * @param file          导入文件
 * @param updateSupport 是否更新已存在数据
 */
export const importData = (file: File, updateSupport: boolean) => {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('updateSupport', updateSupport.toString());
    return request({
        url: '/qms/qcInspectionItem/importData',
        method: 'post',
        data: formData
    });
};

