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


//  Exporting the function as named export
// export  const getByUsrGrpId = async (usrgrp) => {
//     try {
//      const response = await apiService.get(`/api1/getusracces1/${usrgrp}`);
//      if (!response.ok) {
//         throw new Error(`HTTP error! status: ${response.status}`);
//       }
//      console.log(response.data);
//      return response.data;
//     } catch (error) {
//      console.error('Error fetching user groups:', error);
//     }
//  }
 
export const getByUsrGrpId = async (usrgrp) => {
    if (!usrgrp) {
        console.error("Error: usrgrp is not defined or is null.");
        return null;
    }
    try {
        const response = await apiService.get(`/api1/getusracces1/${usrgrp}`);
        if (response.status < 200 || response.status >= 300) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        console.log("Fetched data successfully:", response.data);
        return response.data; // Return the data if successfully fetched
    } catch (error) {
        console.error("Error fetching user groups:", error.message || error);
        throw error; // Re-throw the error to handle it in the caller function
    }
};
