/** * API utility functions for making requests to AeThex API */ export interface ApiResponse { data?: T error?: string message?: string } const API_BASE = process.env.NEXT_PUBLIC_API_URL || '/api' export async function apiCall( method: 'GET' | 'POST' | 'PATCH' | 'DELETE', endpoint: string, body?: Record ): Promise> { try { const response = await fetch(`${API_BASE}${endpoint}`, { method, headers: { 'Content-Type': 'application/json', }, body: body ? JSON.stringify(body) : undefined, }) const data = await response.json() if (!response.ok) { return { error: data.error || `HTTP ${response.status}`, } } return { data: data as T, } } catch (error) { console.error(`API call failed: ${method} ${endpoint}`, error) return { error: error instanceof Error ? error.message : 'Unknown error', } } } // Convenience methods export const api = { get: (endpoint: string) => apiCall('GET', endpoint), post: (endpoint: string, body?: Record) => apiCall('POST', endpoint, body), patch: (endpoint: string, body?: Record) => apiCall('PATCH', endpoint, body), delete: (endpoint: string) => apiCall('DELETE', endpoint), }