import { Game, CreateGameInput, UpdateGameInput } from '../types/game'; const API_BASE = '/api'; async function request(endpoint: string, options?: RequestInit): Promise { const response = await fetch(`${API_BASE}${endpoint}`, { headers: { 'Content-Type': 'application/json', ...options?.headers, }, ...options, }); if (!response.ok) { throw new Error(`API error: ${response.status} ${response.statusText}`); } return response.json(); } export const api = { games: { list: () => request('/games'), create: (data: CreateGameInput) => request('/games', { method: 'POST', body: JSON.stringify(data), }), update: (id: string, data: UpdateGameInput) => request(`/games/${id}`, { method: 'PUT', body: JSON.stringify(data), }), delete: (id: string) => request(`/games/${id}`, { method: 'DELETE', }), }, };