import axiosInstance from '../../../../utils/axiosInstance';

const fetchData= async (search, sort, page, limit) => {
    try {
        const response = await axiosInstance.get(`/level/admin?search=${search}&sort=${sort}&page=${page}&limit=${limit}`);
        return response.data;
    } catch (error) {
        console.error('Error fetching levels:', error);
        throw error;
    }
};

const getLevelById = async (id) => {
    try {
        const response = await axiosInstance.get(`/level/${id}`);
        return response.data;
    } catch (error) {
        console.error(`Error fetching level with ID ${id}:`, error);
        throw error;
    }
};

const updateData = async (id, materialData) => {
    try {
        const response = await axiosInstance.put(`/level/${id}`, materialData);
        return response.data;
    } catch (error) {
        console.error(`Error updating level with ID ${id}:`, error);
        throw error;
    }
};

const uploadMedia = async (id, mediaData) => {
    try {
        const response = await axiosInstance.post(`/level/file/${id}`, mediaData);
        return response.data;
    } catch (error) {
        console.error("Error uploading media:", error);
        throw error;
    }
};

export default{
    fetchData,
    getLevelById,
    uploadMedia,
    updateData,
};
