import { basic as request } from '@/api/request';

/**
 * @description 删除备份数据数据
 * @url /rbac/resource-backup/deleteResourceBackup
 * @method DELETE
 * @author @pubinfo/openapi
 */
export function deleteRbacResourceBackupDeleteResourceBackup<
  R = API.ResponseDataVoid,
  T = API.ResponseDataVoid,
>(
  params: API.deleteRbacResourceBackupDeleteResourceBackupParams,
  options?: Parameters<typeof request.Delete<R, T>>[2],
) {
  return request.Delete<R, T>(
    '/rbac/resource-backup/deleteResourceBackup',
    {},
    {
      params: {
        ...params,
      },
      ...(options || {}),
    },
  );
}

/**
 * @description 查看详情
 * @url /rbac/resource-backup/detail
 * @method GET
 * @author @pubinfo/openapi
 */
export function getRbacResourceBackupDetail<
  R = API.ResponseDataPubResourceBackupBO,
  T = API.ResponseDataPubResourceBackupBO,
>(
  params: API.getRbacResourceBackupDetailParams,
  options?: Parameters<typeof request.Get<R, T>>[1],
) {
  return request.Get<R, T>('/rbac/resource-backup/detail', {
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/**
 * @description 资源导出
 * @url /rbac/resource-backup/exportResourceData
 * @method POST
 * @author @pubinfo/openapi
 */
export function postRbacResourceBackupExportResourceData<
  R = API.ResponseDataPubResourceExportBO,
  T = API.ResponseDataPubResourceExportBO,
>(body: string[], options?: Parameters<typeof request.Post<R, T>>[2]) {
  return request.Post<R, T>('/rbac/resource-backup/exportResourceData', body, {
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
  });
}

/**
 * @description 资源导入
 * @url /rbac/resource-backup/importResourceData
 * @method POST
 * @author @pubinfo/openapi
 */
export function postRbacResourceBackupImportResourceData<
  R = API.ResponseDataVoid,
  T = API.ResponseDataVoid,
>(
  params: API.postRbacResourceBackupImportResourceDataParams,
  body: Record<string, unknown>,
  file?: File,
  options?: Parameters<typeof request.Post<R, T>>[2],
) {
  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) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (Array.isArray(item)) {
          item.forEach(f => formData.append(ele, f || ''));
        }
        else {
          formData.append(ele, JSON.stringify(item));
        }
      }
      else {
        formData.append(ele, item);
      }
    }
  });

  return request.Post<R, T>(
    '/rbac/resource-backup/importResourceData',
    formData,
    {
      params: {
        ...params,
      },
      ...(options || {}),
    },
  );
}

/**
 * @description 查看列表
 * @url /rbac/resource-backup/list
 * @method GET
 * @author @pubinfo/openapi
 */
export function getRbacResourceBackupList<
  R = API.ResponseDataListPubResourceBackupBO,
  T = API.ResponseDataListPubResourceBackupBO,
>(
  params: API.getRbacResourceBackupListParams,
  options?: Parameters<typeof request.Get<R, T>>[1],
) {
  return request.Get<R, T>('/rbac/resource-backup/list', {
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/**
 * @description 恢复数据
 * @url /rbac/resource-backup/restore
 * @method GET
 * @author @pubinfo/openapi
 */
export function getRbacResourceBackupRestore<
  R = API.ResponseDataVoid,
  T = API.ResponseDataVoid,
>(
  params: API.getRbacResourceBackupRestoreParams,
  options?: Parameters<typeof request.Get<R, T>>[1],
) {
  return request.Get<R, T>('/rbac/resource-backup/restore', {
    params: {
      ...params,
    },
    ...(options || {}),
  });
}
