/**
 * Simple test script for Dashboard API endpoints
 * This will help debug if the API endpoints are working
 */

import fetch from 'node-fetch';

const BASE_URL = 'http://localhost:3000/api/surveys/project';
const TREELOGY_ID = 1; // Replace with actual treelogy_id
const AUTH_TOKEN = 'test-token'; // Replace with actual token

const headers = {
  'Authorization': `Bearer ${AUTH_TOKEN}`,
  'Content-Type': 'application/json'
};

async function testDashboardAPI() {
  console.log('🧪 Testing Dashboard API Endpoints...\n');

  try {
    // Test dashboard cards endpoint
    console.log('📊 Testing Dashboard Cards API...');
    const cardsResponse = await fetch(`${BASE_URL}/${TREELOGY_ID}/dashboard/cards`, { headers });
    
    console.log('Status:', cardsResponse.status);
    console.log('Headers:', Object.fromEntries(cardsResponse.headers.entries()));
    
    if (cardsResponse.ok) {
      const cardsData = await cardsResponse.json();
      console.log('✅ Cards API Response:', JSON.stringify(cardsData, null, 2));
    } else {
      const errorText = await cardsResponse.text();
      console.log('❌ Cards API Error:', errorText);
    }

    // Test condition chart endpoint
    console.log('\n📈 Testing Condition Chart API...');
    const conditionResponse = await fetch(`${BASE_URL}/${TREELOGY_ID}/dashboard/charts/condition`, { headers });
    
    console.log('Status:', conditionResponse.status);
    
    if (conditionResponse.ok) {
      const conditionData = await conditionResponse.json();
      console.log('✅ Condition Chart Response:', JSON.stringify(conditionData, null, 2));
    } else {
      const errorText = await conditionResponse.text();
      console.log('❌ Condition Chart Error:', errorText);
    }

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

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

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