import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { QcInspectionTypeVO, QcInspectionTypeForm, QcInspectionTypeQuery } from '@/api/qms/qcInspectionType/types';

/**
 * 查询检测类型列表
 * @param query
 * @returns {*}
 */

export const listQcInspectionType = (query?: QcInspectionTypeQuery): AxiosPromise<QcInspectionTypeVO[]> => {
  return request({
    url: '/qms/qcInspectionType/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询检测类型详细
 * @param typeId
 */
export const getQcInspectionType = (typeId: string | number): AxiosPromise<QcInspectionTypeVO> => {
  return request({
    url: '/qms/qcInspectionType/' + typeId,
    method: 'get'
  });
};

/**
 * 新增检测类型
 * @param data
 */
export const addQcInspectionType = (data: QcInspectionTypeForm) => {
  return request({
    url: '/qms/qcInspectionType',
    method: 'post',
    data: data
  });
};

/**
 * 修改检测类型
 * @param data
 */
export const updateQcInspectionType = (data: QcInspectionTypeForm) => {
  return request({
    url: '/qms/qcInspectionType',
    method: 'put',
    data: data
  });
};

/**
 * 删除检测类型
 * @param typeId
 */
export const delQcInspectionType = (typeId: string | number | Array<string | number>) => {
  return request({
    url: '/qms/qcInspectionType/' + typeId,
    method: 'delete'
  });
};


/**
 * 下拉框查询检测类型列表
 * @param query
 * @returns {*}
 */
export function getQcInspectionTypeList (query) {
    return request({
        url: '/qms/qcInspectionType/getQcInspectionTypeList',
        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/qcInspectionType/importData',
        method: 'post',
        data: formData
    });
};