import apiService from '../APIRequestService/APIServices';

const API_BASE_URL = process.env.REACT_APP_API_BASE_URL;

export const getAllUsers = async () => {
    try {
        const response = await apiService.get(`${API_BASE_URL}/api/getAllAppUser`);
        console.log(response.data);
        return response;
    } catch (error) {
        console.error('Error fetching user groups:', error); 
        throw error; // Consider re-throwing the error for handling in components
    }
}

export const createUser = async (data) => {
    try {
        const response = await apiService.post(`${API_BASE_URL}/api/addOneAppUser`, data);
        console.log(response.data);
        return response;
    } catch (error) {
        console.error('Error creating user:', error);
        throw error;
    }
};

export const updateUser = async (userData) => {
    try {
        const { userId, ...data } = userData;
        const response = await apiService.put(`${API_BASE_URL}/api/updateAppUser/${userId}`, data);
        console.log(response.data);
        return response;
    } catch (error) {
        console.error('Error updating user:', error);
        throw error;
    }
};

export const deleteUser = async (id) => {
    try {
        const response = await apiService.delete(`${API_BASE_URL}/api/deleteAppUser/${id}`);
        console.log(response.data);
        return response;
    } catch (error) {
        console.error('Error deleting user:', error);
        throw error;
    }
};