import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { QcInspectionTemplateVO, QcInspectionTemplateForm, QcInspectionTemplateQuery } from '@/api/qms/qcInspectionTemplate/types';

/**
 * 查询检测模板主列表
 * @param query
 * @returns {*}
 */

export const listQcInspectionTemplate = (query?: QcInspectionTemplateQuery): AxiosPromise<QcInspectionTemplateVO[]> => {
  return request({
    url: '/qms/qcInspectionTemplate/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询检测模板主表详细
 * @param templateId
 */
export const getQcInspectionTemplate = (templateId: string | number): AxiosPromise<QcInspectionTemplateVO> => {
  return request({
    url: '/qms/qcInspectionTemplate/' + templateId,
    method: 'get'
  });
};

/**
 * 新增检测模板主表
 * @param data
 */
export const addQcInspectionTemplate = (data: QcInspectionTemplateForm) => {
  return request({
    url: '/qms/qcInspectionTemplate',
    method: 'post',
    data: data
  });
};

/**
 * 修改检测模板主表
 * @param data
 */
export const updateQcInspectionTemplate = (data: QcInspectionTemplateForm) => {
  return request({
    url: '/qms/qcInspectionTemplate',
    method: 'put',
    data: data
  });
};

/**
 * 删除检测模板主表
 * @param templateId
 */
export const delQcInspectionTemplate = (templateId: string | number | Array<string | number>) => {
  return request({
    url: '/qms/qcInspectionTemplate/' + templateId,
    method: 'delete'
  });
};


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