// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** 获取文件路径 POST /file/getFileById */
export async function postFileGetFileById(body: API.GetById, options?: { [key: string]: any }) {
  return request<API.Response & { data?: API.FileResponse }>(`/api/v1/file/getFileById`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 上传照片 POST /file/uploadImage */
export async function postFileUploadImage(body: {}, file?: File, options?: { [key: string]: any }) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      formData.append(
        ele,
        typeof item === 'object' && !(item instanceof File) ? JSON.stringify(item) : item,
      );
    }
  });

  return request<API.Response & { data?: API.File; msg?: string }>(`/api/v1/file/uploadImage`, {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}

export async function postFileUploadFile(body: {}, file?: File, options?: { [key: string]: any }) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      formData.append(
          ele,
          typeof item === 'object' && !(item instanceof File) ? JSON.stringify(item) : item,
      );
    }
  });

  return request<API.Response & { data?: API.File; msg?: string }>(`/api/v1/file/uploadFile`, {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}
