/**
 * Test all chart endpoints
 */

import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

async function testAllCharts() {
  console.log('🧪 Testing All Chart Endpoints...\n');

  const endpoints = [
    { name: 'Cards', url: 'http://172.17.46.11:63318/api/surveys/project/1/dashboard/cards' },
    { name: 'Condition Chart', url: 'http://172.17.46.11:63318/api/surveys/project/1/dashboard/charts/condition' },
    { name: 'Remarks Chart', url: 'http://172.17.46.11:63318/api/surveys/project/1/dashboard/charts/remarks' },
    { name: 'Ownership Chart', url: 'http://172.17.46.11:63318/api/surveys/project/1/dashboard/charts/ownership' },
    { name: 'Species Chart', url: 'http://172.17.46.11:63318/api/surveys/project/1/dashboard/charts/species' },
    { name: 'Economic Importance Chart', url: 'http://172.17.46.11:63318/api/surveys/project/1/dashboard/charts/economic-importance' }
  ];

  for (const endpoint of endpoints) {
    try {
      console.log(`\n📊 Testing ${endpoint.name}...`);
      const { stdout } = await execAsync(`curl -s "${endpoint.url}"`);
      const response = JSON.parse(stdout);
      
      if (response.success) {
        console.log(`✅ ${endpoint.name}: SUCCESS`);
        if (response.data && Array.isArray(response.data)) {
          console.log(`   Data points: ${response.data.length}`);
          if (response.data.length > 0) {
            console.log(`   Sample: ${JSON.stringify(response.data[0])}`);
          }
        } else if (response.data && typeof response.data === 'object') {
          console.log(`   Data: ${JSON.stringify(response.data)}`);
        }
      } else {
        console.log(`❌ ${endpoint.name}: ${response.message}`);
      }
    } catch (error) {
      console.log(`❌ ${endpoint.name}: Error - ${error.message}`);
    }
  }

  console.log('\n🏁 All chart tests completed!');
}

// Run the test
testAllCharts().catch(console.error);
