/**
 * Test API using curl commands
 */

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

const execAsync = promisify(exec);

async function testAPI() {
  console.log('🧪 Testing Dashboard API with curl...\n');

  try {
    // Test 1: Check if server is running
    console.log('1️⃣ Testing server connectivity...');
    const { stdout: healthOutput } = await execAsync('curl -s http://172.17.46.11:63318/');
    console.log('✅ Server response:', healthOutput.trim());

    // Test 2: Test dashboard cards endpoint
    console.log('\n2️⃣ Testing Dashboard Cards API...');
    const { stdout: cardsOutput } = await execAsync('curl -s http://172.17.46.11:63318/api/surveys/project/1/dashboard/cards');
    console.log('✅ Cards API Response:');
    console.log(JSON.stringify(JSON.parse(cardsOutput), null, 2));

    // Test 3: Test condition chart endpoint
    console.log('\n3️⃣ Testing Condition Chart API...');
    const { stdout: conditionOutput } = await execAsync('curl -s http://172.17.46.11:63318/api/surveys/project/1/dashboard/charts/condition');
    console.log('✅ Condition Chart Response:');
    console.log(JSON.stringify(JSON.parse(conditionOutput), null, 2));

    // Test 4: Test species chart endpoint
    console.log('\n4️⃣ Testing Species Chart API...');
    const { stdout: speciesOutput } = await execAsync('curl -s http://172.17.46.11:63318/api/surveys/project/1/dashboard/charts/species');
    console.log('✅ Species Chart Response:');
    console.log(JSON.stringify(JSON.parse(speciesOutput), null, 2));

  } catch (error) {
    console.error('❌ Error testing API:', error.message);
  }

  console.log('\n🏁 API test completed!');
}

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