/* eslint-disable */
// @ts-ignore
import request from '@/http/vue-query';
import { CustomRequestOptions } from '@/http/types';

import * as API from './types';

/** 获取文件列表 分页获取文件列表，支持多种过滤条件 GET /files */
export async function filesUsingGet({
  params,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.filesUsingGetParams;
  options?: CustomRequestOptions;
}) {
  return request<
    API.Response & {
      data?: API.FileListResponse;
    }
  >('/files', {
    method: 'GET',
    params: {
      // page has a default value: 1
      page: '1',
      // page_size has a default value: 10
      page_size: '10',

      // sort_by has a default value: created_at
      sort_by: 'created_at',
      // sort_order has a default value: desc
      sort_order: 'desc',
      ...params,
    },
    ...(options || {}),
  });
}

/** 获取文件信息 根据文件ID获取文件详细信息 GET /files/${param0} */
export async function filesIdUsingGet({
  params,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.filesIdUsingGetParams;
  options?: CustomRequestOptions;
}) {
  const { id: param0, ...queryParams } = params;

  return request<
    API.Response & {
      data?: API.FileResponse;
    }
  >(`/files/${param0}`, {
    method: 'GET',
    params: { ...queryParams },
    ...(options || {}),
  });
}

/** 删除文件 根据文件ID删除文件 DELETE /files/${param0} */
export async function filesIdUsingDelete({
  params,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.filesIdUsingDeleteParams;
  options?: CustomRequestOptions;
}) {
  const { id: param0, ...queryParams } = params;

  return request<
    API.Response & {
      message?: string;
    }
  >(`/files/${param0}`, {
    method: 'DELETE',
    params: { ...queryParams },
    ...(options || {}),
  });
}

/** 下载文件 根据文件ID下载文件 GET /files/${param0}/download */
export async function filesIdDownloadUsingGet({
  params,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.filesIdDownloadUsingGetParams;
  options?: CustomRequestOptions;
}) {
  const { id: param0, ...queryParams } = params;

  return request<string>(`/files/${param0}/download`, {
    method: 'GET',
    params: { ...queryParams },
    ...(options || {}),
  });
}

/** 重命名文件 根据文件ID重命名文件 PUT /files/${param0}/rename */
export async function filesIdRenameUsingPut({
  params,
  body,
  options,
}: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.filesIdRenameUsingPutParams;
  body: API.FilesIdRenameUsingPutBody;
  options?: CustomRequestOptions;
}) {
  const { id: param0, ...queryParams } = params;

  return request<
    API.Response & {
      message?: string;
    }
  >(`/files/${param0}/rename`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    params: { ...queryParams },
    data: body,
    ...(options || {}),
  });
}

/** 批量删除文件 批量删除多个文件 POST /files/batch-delete */
export async function filesBatchDeleteUsingPost({
  body,
  options,
}: {
  body: API.FilesBatchDeleteUsingPostBody;
  options?: CustomRequestOptions;
}) {
  return request<
    API.Response & {
      message?: string;
    }
  >('/files/batch-delete', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 批量上传文件 批量上传多个文件，最多支持10个文件同时上传 POST /files/batch-upload */
export async function filesBatchUploadUsingPost({
  body,
  options,
}: {
  body: API.FilesBatchUploadUsingPostBody;
  options?: CustomRequestOptions;
}) {
  const formData = new FormData();

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

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<
    API.Response & {
      data?: API.BatchFileUploadResponse;
    }
  >('/files/batch-upload', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: formData,
    ...(options || {}),
  });
}

/** 获取文件统计信息 获取文件相关的统计信息 GET /files/stats */
export async function filesStatsUsingGet({
  options,
}: {
  options?: CustomRequestOptions;
}) {
  return request<
    API.Response & {
      data?: API.FileStats;
    }
  >('/files/stats', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 上传文件 上传单个文件 POST /files/upload */
export async function filesUploadUsingPost({
  body,
  file,
  options,
}: {
  body: API.FilesUploadUsingPostBody;
  file?: File;
  options?: CustomRequestOptions;
}) {
  const formData = new FormData();

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

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

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<
    API.Response & {
      data?: API.FileResponse;
    }
  >('/files/upload', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: formData,
    ...(options || {}),
  });
}
