import axios from 'axios'; const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'; // Create axios instance with default config export const api = axios.create({ baseURL: `${API_URL}/api`, headers: { 'Content-Type': 'application/json', }, }); // Types export interface Restaurant { id: number; place_id: string; name: string; address: string; latitude: number; longitude: number; average_rating: number | null; total_ratings: number; created_at: string; has_toast: boolean | null; distance?: number; } export interface Rating { id: number; rating: number; review: string; created_at: string; } export interface RestaurantDetail extends Restaurant { recent_ratings: Rating[]; } export interface PlaceSearchResult { place_id: string; name: string; address: string; latitude: number; longitude: number; category?: string; cuisine?: string; confidence?: string; distance?: number; source?: string; restaurant_id?: number; has_toast?: boolean | null; } export interface CreateRatingData { rating: number; review: string; } // API functions export const restaurantApi = { // Get nearby restaurants getNearby: async (lat: number, lng: number, radius: number = 5) => { const response = await api.get('/restaurants/nearby/', { params: { lat, lng, radius } }); return response.data; }, // Get restaurant details getById: async (id: number) => { const response = await api.get(`/restaurants/${id}/`); return response.data; }, // Create restaurant create: async (data: Omit) => { const response = await api.post('/restaurants/', data); return response.data; }, // Add rating addRating: async (restaurantId: number, data: CreateRatingData) => { const response = await api.post(`/restaurants/${restaurantId}/ratings/`, data); return response.data; }, // Update toast status updateToastStatus: async (restaurantId: number, hasToast: boolean) => { const response = await api.patch(`/restaurants/${restaurantId}/toast-status/`, { has_toast: hasToast }); return response.data; }, // Search places searchPlaces: async (lat: number, lng: number, radius: number = 1000) => { const response = await api.get('/search/places/', { params: { lat, lng, radius } }); return response.data; }, // Seed data seedData: async (lat: number, lng: number) => { const response = await api.post('/seed/', { lat, lng }); return response.data; } };