import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { StructuresVO, StructuresForm, StructuresQuery } from '@/api/system/business/structures/types';
import { ItemsVO } from '@/api/system/business/items/types';

/**
 * 查询【盲注结构】列表
 * @param query
 * @returns {*}
 */

export const listStructures = (query?: StructuresQuery): AxiosPromise<StructuresVO[]> => {
  return request({
    url: '/business/structures/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询【盲注结构】详细
 * @param id
 */
export const getStructures = (id: string | number): AxiosPromise<StructuresVO> => {
  return request({
    url: '/business/structures/' + id,
    method: 'get'
  });
};

/**
 * 新增【盲注结构】
 * @param data FormData
 */
export const addStructures = (data: FormData) => {
  return request({
    url: '/business/structures',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};

/**
 * 修改【盲注结构】
 * @param data FormData
 */
export const updateStructures = (data: FormData) => {
  return request({
    url: '/business/structures/edit',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};
/**
 * 删除【盲注结构】
 * @param id
 */
export const delStructures = (id: string | number | Array<string | number>) => {
  return request({
    url: '/business/structures/' + id,
    method: 'delete'
  });
};

/**
 * 下载盲注级别导入模板
 */
export const downloadImportTemplate = async () => {
  const res = await request({
    url: '/business/levels/importTemplate',
    method: 'POST',
    responseType: 'blob'
  });
  return res;
};

export const importData = async (file: File) => {
  const formData = new FormData();
  formData.append('file', file); // 后端接收的参数名是 "file"

  const res = await request({
    url: '/business/levels/importData',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });

  return res;
};

export const selectBlingStructuresInfo = (): AxiosPromise<StructuresVO> => {
  return request({
    url: '/business/structures/selectBlingStructuresInfo',
    method: 'get'
  });
};
