#!/usr/bin/env node

/**
 * Test script to run Firebase scraper directly
 */

import { runFirebaseEventScraper, initializeScraperOrganization } from './src/lib/firebaseEventScraper.js';
import { config } from 'dotenv';

// Load environment variables
config();

async function test() {
  console.log('🧪 Testing Firebase Event Scraper');
  console.log('================================');
  
  try {
    // Initialize organization first
    console.log('🔧 Initializing scraper organization...');
    const initialized = await initializeScraperOrganization();
    console.log(`Organization initialized: ${initialized}`);
    
    // Run the scraper
    console.log('\n🚀 Running Firebase scraper...');
    const result = await runFirebaseEventScraper();
    
    console.log('\n📊 Results:');
    console.log(`Success: ${result.success}`);
    console.log(`Message: ${result.message}`);
    
    if (result.newEvents && result.newEvents.length > 0) {
      console.log(`\n🎉 New Events Added (${result.newEvents.length}):`);
      result.newEvents.forEach((event, index) => {
        console.log(`${index + 1}. ${event.title}`);
        console.log(`   Venue: ${event.venue}`);
        console.log(`   Category: ${event.category}`);
        console.log(`   Price Range: ${event.priceRange}`);
        console.log(`   Start: ${event.startTime}`);
        if (event.imageUrl) {
          console.log(`   Image: ${event.imageUrl}`);
        }
        console.log('');
      });
    }
    
  } catch (error) {
    console.error('💥 Test failed:', error);
  }
}

test();