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

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

const createData = async (teacherData) => {
    try {
        const response = await axiosInstance.post(`/register/teacher`, teacherData);
        return response.data;
    } catch (error) {
        console.error('Error adding teacher:', error);
        throw error;
    }
};

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

const deleteData = async (id) => {
    try {
        const response = await axiosInstance.delete(`/user/delete/${id}`);
        return response.data;
    } catch (error) {
        console.error(`Error deleting teacher with ID ${id}:`, error);
        throw error;
    }
};

export default{
    fetchData,
    createData,
    updateData,
    deleteData
};
