import { request } from '@/plugins/http-fetch';

/**
 * 获取下拉框数据
 * @returns object
 */
export function getBakFile() {
  return request({
    url: '/lm/table/list',
    method: 'get',
  });
}

/**
 * 获取对应类型的文件列表
 * @param query 查询参数
 * @returns object
 */
export function getBakFileList(query: Record<string, any>) {
  return request({
    url: '/lm/file/list',
    method: 'get',
    params: query,
  });
}

/**
 * 下载远端文件
 * @param query 查询参数
 * @returns object
 */
export function downFile(query: Record<string, any>) {
  return request({
    url: `/lm/file/${query.fileName}`,
    method: 'get',
    params: query,
    responseType: 'blob',
    timeout: 180_000,
  });
}

/**
 * 删除远端获取文件
 * @param query 查询参数
 * @returns object
 */
export function delFile(query: Record<string, any>) {
  return request({
    url: `/lm/file/${query.fileName}`,
    method: 'delete',
    params: query,
  });
}

/**
 * 更新FTP信息
 * @param data 数据
 * @returns object
 */
export function updateFTPInfo(data: Record<string, any>) {
  return request({
    url: `/lm/table/ftp`,
    method: 'post',
    data: data,
  });
}

/**
 * 获取FTP信息
 * @param data 数据
 * @returns object
 */
export function getFTPInfo() {
  return request({
    url: `/lm/table/ftp`,
    method: 'get',
  });
}

/**
 * 发送FTP文件
 * @param data 数据
 * @returns object
 */
export function putFTPInfo(filePath: string, fileName: string) {
  return request({
    url: `/lm/table/ftp`,
    method: 'put',
    data: { filePath, fileName },
  });
}
