// Test actual API response to see what's being returned
import axios from 'axios';

const API_URL = process.env.VITE_API_Dep_URL || 'http://localhost:5000';

async function testAPI() {
  try {
    console.log('🔍 Testing GET /api/website endpoint...\n');
    
    const response = await axios.get(`${API_URL}/api/website`, {
      params: { limit: 5 }
    });

    console.log(`✅ Response received: ${response.data.data.length} items\n`);

    response.data.data.forEach((item, index) => {
      console.log(`${index + 1}. ${item.Title}`);
      console.log(`   ID: ${item._id}`);
      console.log(`   submittedBy: ${item.submittedBy ? 'EXISTS' : '❌ NULL'}`);
      
      if (item.submittedBy) {
        console.log(`   - ID: ${item.submittedBy._id || item.submittedBy}`);
        console.log(`   - userName: ${item.submittedBy.userName || 'MISSING'}`);
        console.log(`   - email: ${item.submittedBy.email || 'MISSING'}`);
      }
      console.log('');
    });

    // Check if any have null submittedBy
    const nullCount = response.data.data.filter(item => !item.submittedBy).length;
    const objectIdCount = response.data.data.filter(item => 
      item.submittedBy && typeof item.submittedBy === 'string'
    ).length;
    const populatedCount = response.data.data.filter(item => 
      item.submittedBy && typeof item.submittedBy === 'object'
    ).length;

    console.log('📊 Summary:');
    console.log(`   ❌ Null submittedBy: ${nullCount}`);
    console.log(`   ⚠️  Unpopulated (ObjectId string): ${objectIdCount}`);
    console.log(`   ✅ Properly populated: ${populatedCount}`);

  } catch (error) {
    console.error('❌ Error:', error.message);
    if (error.response) {
      console.error('Response:', error.response.data);
    }
  }
}

testAPI();
