import api from './client';

export const apiGetDocument = async ({ user, path, division, category }: { user: string, path: string, division: string, category: 'all' | 'folder' }) => {
   const response = await api.get(`mobile/document?user=${user}&path=${path}&division=${division}&category=${category}`);
   return response.data;
};

export const apiGetDocumentInformasi = async ({ user, item, cat }: { user: string, item: string, cat: 'share' | 'lainnya' }) => {
   const response = await api.get(`mobile/document/more?user=${user}&item=${item}&cat=${cat}`);
   return response.data;
};

export const apiDocumentRename = async (data: { name: string, user: string, id: string, path: string, idDivision: string, extension: string }) => {
   const response = await api.put(`/mobile/document`, data)
   return response.data;
};

export const apiDocumentDelete = async (data: { user: string, data: any[] }) => {
   const response = await api.delete(`/mobile/document`, { data })
   return response.data
};

export const apiCreateFolderDocument = async ({ data }: { data: { name: string, path: string, idDivision: string, user: string } }) => {
   const response = await api.post(`/mobile/document`, data)
   return response.data;
};

export const apiUploadFileDocument = async ({ data }: { data: FormData }) => {
   const response = await api.post(`/mobile/document/upload`, data, {
      headers: { 'Content-Type': 'multipart/form-data' },
   })
   return response.data;
};

export const apiMoveDocument = async (data: { path: string, dataItem: any[], user: string }) => {
   const response = await api.post(`/mobile/document/more`, data)
   return response.data;
};

export const apiCopyDocument = async (data: { path: string, dataItem: any[], user: string, idDivision: string }) => {
   const response = await api.put(`/mobile/document/more`, data)
   return response.data;
};

export const apiShareDocument = async (data: { dataDivision: any[], dataItem: any[], user: string }) => {
   const response = await api.delete(`/mobile/document/more`, { data })
   return response.data;
};
