/**
 * Test backend connection utility
 * Useful for debugging connectivity issues
 */
import { apiClient } from '@/shared/api/client';
import { env } from '@/shared/config/env';

export async function testBackendConnection(): Promise<{
  success: boolean;
  message: string;
  details?: any;
}> {
  try {
    console.log('Testing backend connection to:', env.API_URL);
    
    // Test 1: Simple GET request
    const testResponse = await apiClient.get('/api/v1/test');
    console.log('✅ Backend test endpoint response:', testResponse);
    
    return {
      success: true,
      message: 'Backend is reachable',
      details: testResponse,
    };
  } catch (error: any) {
    console.error('❌ Backend connection test failed:', error);
    
    return {
      success: false,
      message: error?.message || 'Failed to connect to backend',
      details: {
        url: env.API_URL,
        error: error?.message,
        code: error?.code,
      },
    };
  }
}
