import client from './client';
import { API_ENDPOINTS } from './ApiSources';


/**
 * Get all users
 * @returns {Promise<Object>} All users data
 */
export const getUsers = async () => {
    try {
        responce = await client.get(API_ENDPOINTS.USERS.LIST);
        return responce.data;
    } catch (error) {
        throw error.response?.data || error.message;
    }
};

/**
 * Get user by id
 * @param {number} id - User id
 * @returns {Promise<Object>} User data
 */
export const getUserById = async (id) => {
    try {
        const response = await client.get(API_ENDPOINTS.USERS.BY_ID(id));
        return response.data;
    } catch (error) {
        throw error.response?.data || error.message;
    }
};

/**
 * Get all user tasks
 * @param {number} id - User id
 * @returns {Promise<Object>} All user tasks data
 */
export const getUserTasks = async (id) => {
    try {
        const response = await client.get(API_ENDPOINTS.USERS.TASKS(id));
        return response.data;
    } catch (error) {
        throw error.response?.data || error.message;
    }
};