import api from './client';

export const apiGetDiscussionGeneral = async ({ user, active, search, group, page }: { user: string, active: string, search: string, group?: string, page?: number }) => {
   const response = await api.get(`mobile/discussion-general?user=${user}&active=${active}&group=${group}&search=${search}&page=${page}`);
   return response.data;
};

export const apiGetDiscussionGeneralOne = async ({ id, user, cat }: { id: string, user: string, cat: string }) => {
   const response = await api.get(`mobile/discussion-general/${id}?user=${user}&cat=${cat}`);
   return response.data;
};

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

export const apiEditDiscussionGeneral = async (data: FormData, id: string) => {
   const response = await api.put(`/mobile/discussion-general/${id}`, data, {
      headers: { 'Content-Type': 'multipart/form-data' },
   })
   return response.data;
};

export const apiDeleteDiscussionGeneral = async (data: { user: string, active: boolean }, id: string) => {
   const response = await api.delete(`mobile/discussion-general/${id}`, { data });
   return response.data;
};

export const apiUpdateStatusDiscussionGeneral = async ({ id, data }: { id: string, data: { status: number, user: string } }) => {
   const response = await api.post(`/mobile/discussion-general/${id}`, data)
   return response.data;
};

export const apiSendDiscussionGeneralCommentar = async ({ id, data }: { id: string, data: { desc: string, user: string } }) => {
   const response = await api.post(`/mobile/discussion-general/${id}/comment`, data)
   return response.data;
};

export const apiSendDiscussionGeneralCommentarWithFile = async (id: string, data: FormData) => {
   const response = await api.post(`/mobile/discussion-general/${id}/comment`, data, {
      headers: { 'Content-Type': 'multipart/form-data' },
   })
   return response.data;
};

export const apiUpdateDiscussionGeneralCommentar = async ({ id, data }: { id: string, data: { desc: string, user: string, filesToRemove?: string[] } }) => {
   const response = await api.put(`/mobile/discussion-general/${id}/comment`, data)
   return response.data;
};

export const apiDeleteDiscussionGeneralCommentar = async ({ id, data }: { id: string, data: { user: string } }) => {
   const response = await api.delete(`/mobile/discussion-general/${id}/comment`, { data })
   return response.data;
};

export const apiAddMemberDiscussionGeneral = async ({ data, id }: { data: { user: string, member: any[] }, id: string }) => {
   const response = await api.post(`/mobile/discussion-general/${id}/member`, data)
   return response.data;
};

export const apiDeleteMemberDiscussionGeneral = async (data: { user: string, idUser: string }, id: string) => {
   const response = await api.delete(`mobile/discussion-general/${id}/member`, { data });
   return response.data;
};

export const apiGetDiscussion = async ({ user, search, division, active, page }: { user: string, search: string, division: string, active?: string, page?: number }) => {
   const response = await api.get(`mobile/discussion?user=${user}&active=${active}&search=${search}&division=${division}&page=${page}`);
   return response.data;
};

export const apiGetDiscussionOne = async ({ id, user, cat }: { id: string, user: string, cat: 'data' | 'comment' | 'file' }) => {
   const response = await api.get(`mobile/discussion/${id}?user=${user}&cat=${cat}`);
   return response.data;
};

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

export const apiEditDiscussion = async (data: FormData, id: string) => {
   const response = await api.post(`/mobile/discussion/${id}`, data, {
      headers: { 'Content-Type': 'multipart/form-data' },
   })
   return response.data;
};

export const apiArchiveDiscussion = async (data: { user: string, active: boolean }, id: string) => {
   const response = await api.put(`mobile/discussion/${id}`, data)
   return response.data
};

export const apiOpenCloseDiscussion = async (data: { user: string, status: number }, id: string) => {
   const response = await api.delete(`mobile/discussion/${id}`, { data })
   return response.data
};

export const apiSendDiscussionCommentar = async ({ data, id }: { data: { user: string, comment: string }, id: string }) => {
   const response = await api.post(`/mobile/discussion/${id}/comment`, data)
   return response.data;
};

export const apiSendDiscussionCommentarWithFile = async (id: string, data: FormData) => {
   const response = await api.post(`/mobile/discussion/${id}/comment`, data, {
      headers: { 'Content-Type': 'multipart/form-data' },
   })
   return response.data;
};

export const apiEditDiscussionCommentar = async ({ data, id }: { data: { user: string, comment: string, filesToRemove?: string[] }, id: string }) => {
   const response = await api.put(`/mobile/discussion/${id}/comment`, data)
   return response.data;
};

export const apiDeleteDiscussionCommentar = async ({ data, id }: { data: { user: string }, id: string }) => {
   const response = await api.delete(`/mobile/discussion/${id}/comment`, { data })
   return response.data;
};
