import api from 'src/config/api';
import { FilePagintaionResponse, FileTree } from 'src/types/files';
import { QueryParams } from 'src/utils/files';

export const getFileList = (
  folderId?: number | string,
  queryParams?: QueryParams,
) =>
  api.get<FilePagintaionResponse>('files', {
    params: {
      folderId,
      order: queryParams?.order,
      orderBy: queryParams?.orderBy,
      q: queryParams?.query,
      page: queryParams?.page || 1,
      limit: queryParams?.limit,
    },
  });

export const getFileTree = (id: number | string) =>
  api.get<FileTree>(`files/${id}/tree`);

export const getFileNameExtension = (fileName: string) =>
  fileName?.split('.').pop();

export const updateUserCoverPicture = (id: number, url: string) =>
  api.put(`users/${id}/cover-picture`, { url });

export const updateProfilePhoto = async (id: number, url: string) =>
  api.put(`users/${id}/profile-picture`, { url });
