import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { QcInspectionItemCategoryVO, QcInspectionItemCategoryForm, QcInspectionItemCategoryQuery } from '@/api/qms/qcInspectionItemCategory/types';

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

export const listQcInspectionItemCategory = (query?: QcInspectionItemCategoryQuery): AxiosPromise<QcInspectionItemCategoryVO[]> => {
  return request({
    url: '/qms/qcInspectionItemCategory/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询检测项类别详细
 * @param categoryId
 */
export const getQcInspectionItemCategory = (categoryId: string | number): AxiosPromise<QcInspectionItemCategoryVO> => {
  return request({
    url: '/qms/qcInspectionItemCategory/' + categoryId,
    method: 'get'
  });
};

/**
 * 新增检测项类别
 * @param data
 */
export const addQcInspectionItemCategory = (data: QcInspectionItemCategoryForm) => {
  return request({
    url: '/qms/qcInspectionItemCategory',
    method: 'post',
    data: data
  });
};

/**
 * 修改检测项类别
 * @param data
 */
export const updateQcInspectionItemCategory = (data: QcInspectionItemCategoryForm) => {
  return request({
    url: '/qms/qcInspectionItemCategory',
    method: 'put',
    data: data
  });
};

/**
 * 删除检测项类别
 * @param categoryId
 */
export const delQcInspectionItemCategory = (categoryId: string | number | Array<string | number>) => {
  return request({
    url: '/qms/qcInspectionItemCategory/' + categoryId,
    method: 'delete'
  });
};


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

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