import axios from "axios"; import { Platform } from "react-native"; const API_BASE_URL = Platform.select({ android: "http://10.0.2.2:3000", // Android emulator maps this to host's localhost ios: "http://localhost:3000", default: process.env.EXPO_PUBLIC_API_URL || "http://localhost:3000", }); export interface FitnessProfile { id?: string; clientId: string; height?: number; weight?: number; goals?: string; fitnessLevel: "beginner" | "intermediate" | "advanced"; medicalConditions?: string; dietaryRestrictions?: string; preferredWorkoutTime?: "morning" | "afternoon" | "evening"; workoutFrequency?: number; } export const fitnessProfileApi = { getFitnessProfile: async ( userId: string, token: string, ): Promise => { try { console.log( "Getting fitness profile with URL:", `${API_BASE_URL}/api/users/${userId}/fitness-profile`, ); const response = await axios.get( `${API_BASE_URL}/api/users/${userId}/fitness-profile`, { headers: { Authorization: `Bearer ${token}`, }, }, ); return response.data; } catch (error: any) { console.error( "Error fetching fitness profile:", error.message, error.response?.data, ); throw error; } }, updateFitnessProfile: async ( userId: string, data: Partial, token: string, ): Promise => { try { const response = await axios.put( `${API_BASE_URL}/api/users/${userId}/fitness-profile`, data, { headers: { Authorization: `Bearer ${token}`, }, }, ); return response.data; } catch (error: any) { console.error( "Error updating fitness profile:", error.message, error.response?.data, ); throw error; } }, createFitnessProfile: async ( data: Omit, token: string, ): Promise => { try { const response = await axios.post( `${API_BASE_URL}/api/users/${data.clientId}/fitness-profile`, data, { headers: { Authorization: `Bearer ${token}`, }, }, ); return response.data; } catch (error: any) { console.error( "Error creating fitness profile:", error.message, error.response?.data, ); throw error; } }, };