import axios from 'axios'; const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000'; const api = axios.create({ baseURL: API_URL, withCredentials: true, }); // Auth endpoints export const authApi = { createAnonymous: (name) => api.post('/auth/anonymous', { name }), register: (email, password, name) => api.post('/auth/register', { email, password, name }), login: (email, password) => api.post('/auth/login', { email, password }), }; // Rooms endpoints export const roomsApi = { create: (hostId, questionPackId, settings) => api.post('/rooms', { hostId, questionPackId, settings }), getByCode: (code) => api.get(`/rooms/${code}`), join: (roomId, userId, name, role) => api.post(`/rooms/${roomId}/join`, { userId, name, role }), updateQuestionPack: (roomId, questionPackId) => api.patch(`/rooms/${roomId}/question-pack`, { questionPackId }), }; // Questions endpoints export const questionsApi = { createPack: (data) => api.post('/questions/packs', data), getPacks: (userId) => api.get('/questions/packs', { params: { userId } }), getPack: (id) => api.get(`/questions/packs/${id}`), updatePack: (id, data) => api.put(`/questions/packs/${id}`, data), deletePack: (id) => api.delete(`/questions/packs/${id}`), }; // Stats endpoints export const statsApi = { createHistory: (data) => api.post('/stats/game-history', data), getHistory: (userId) => api.get(`/stats/game-history/${userId}`), getUserStats: (userId) => api.get(`/stats/user/${userId}`), }; export default api;