import qs from 'query-string';
import request from '../utils/request';
import { Result } from './types';

export interface FileFields {
  searchValue: string;
  createBy: string;
  createTime: string;
  updateBy: string;
  updateTime: string;
  remark: string;
  params: Record<string, any>;
  fileId: string;
  fileName: string;
  filePath: string;
  type: string;
  picType: string;
  fileContent: string;
  isSvg: string; // 1 是 2 否
}

interface UploadResultProps {
  url: string;
  name: string;
}

export const uploadApi = async (data: FormData) => {
  return await request<Result<UploadResultProps>>({
    url: '/file/upload',
    data,
    method: 'post',
  });
};

interface GetFileList_Params {
  type: string;
  picType: string;
}

export const getListApi = async (params: GetFileList_Params) => {
  const { data } = await request<Result<FileFields[]>>({
    url: '/file/list?' + qs.stringify(params),
  });
  return data || [];
};

export const delApi = async (deleteKeys: string) => {
  return await request({
    url: `/file/delete/${deleteKeys || ''}`,
    method: 'get',
  });
};
