import api from "../lib/axios";


export const getCompany = async(companyId) => {
    try {
        const endpoint = `/companies/${companyId}`;
        const {data} = await api.get(endpoint);
        return data;
    } catch (error) {
        console.log(error);
        return null;
    }
}

export const updateCompany = async(companyId, formData) => {
    try {
        const endpoint = `/companies/${companyId}`;
        const {data} = await api.patch(endpoint, formData);
        return data;
    } catch (error) {
        console.log(error);
        return null;
    }
}

export const getUsers = async(companyId) => {
    try {
        const endpoint = `/users?company=${companyId}`;
        const {data} = await api.get(endpoint);
        console.log(data);
        return data;
    } catch (error) {
        console.log(error);
        return null;
    }
}

export const getBudgets = async(filter) => {
    try {
        const endpoint = `/budgets/${filter}`;
        const {data} = await api.get(endpoint);
        // console.log(data);
        return data;
    } catch (error) {
        console.log(error);
        return null;
    }
}


export const updateBudget = async(id, formData) => {
    try {
        const endpoint = `/budgets/${id}`;
        const {data} = await api.patch(endpoint, formData);
        return data;
    } catch (error) {
        console.log(error);
        return null;
    }
}

export const createBudget = async(formData) => {
    try {
        const endpoint = `/budgets`;
        const {data} = await api.post(endpoint, formData);
        return data;
    } catch (error) {
        console.log(error);
        return null;
    }
}

export const deleteBudget = async(id) => {
    try {
        const endpoint = `/budgets/${id}`;
        const {data} = await api.delete(endpoint);
        return data;
    } catch (error) {
        console.log(error);
        return null;
    }
}


// export const editCompany = async(companyId, formData) => {
//     try {
//         const endpoint = `/companies/${companyId}`;
//         const {data} = await api.patch(endpoint, formData);
//         return data;
//     } catch (error) {
//         console.log(error);
//         return null;
//     }
// }