// Use environment variable for API URL
// Set EXPO_PUBLIC_API_URL in your .env file
const getApiBaseUrl = (): string => {
  const envUrl = process.env.EXPO_PUBLIC_API_URL;

  if (envUrl) {
    return envUrl;
  }

  // Fallback for development if not set
  if (__DEV__) {
    console.warn(
      "EXPO_PUBLIC_API_URL not set in .env - using default localhost",
    );
    return "http://localhost:3000";
  }

  // Production MUST have URL set
  throw new Error(
    "EXPO_PUBLIC_API_URL must be set in production environment variables",
  );
};

export const API_BASE_URL = getApiBaseUrl();

export const API_ENDPOINTS = {
  AUTH: {
    LOGIN: "/api/auth/login",
    REGISTER: "/api/auth/register",
  },
  PROFILE: {
    FITNESS: "/api/fitness-profile",
  },
  CLIENTS: "/api/clients",
  USERS: {
    LIST: "/api/users",
    STATISTICS: "/api/users/statistics",
    GYM: "/api/users/gym",
  },
  GYMS: "/api/gyms",
  ATTENDANCE: {
    CHECK_IN: "/api/attendance/check-in",
    CHECK_OUT: "/api/attendance/check-out",
    HISTORY: "/api/attendance/history",
  },
  RECOMMENDATIONS: "/api/recommendations",
  FITNESS_GOALS: {
    LIST: "/api/fitness-goals",
    CREATE: "/api/fitness-goals",
    GET: (id: string) => `/api/fitness-goals/${id}`,
    UPDATE: (id: string) => `/api/fitness-goals/${id}`,
    DELETE: (id: string) => `/api/fitness-goals/${id}`,
    COMPLETE: (id: string) => `/api/fitness-goals/${id}/complete`,
  },
};
