import api from './client';

export const apiGetProfile = async ({ id }: { id: string }) => {
   const response = await api.get(`mobile/user/${id}`);
   return response.data;
};

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

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

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

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

export const apiToggleApprover = async (data: { user: string, isApprover: boolean }, id: string) => {
   const response = await api.patch(`mobile/user/${id}`, data)
   return response.data
};

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