import { ScraperService } from './scraper-service';

async function main() {
  const scraperService = new ScraperService();
  
  try {
    console.log('Scraping in progress...\n');
    
    const results = await scraperService.scrapeAll();
    
    // Show completion status for each vendor
    results.forEach(result => {
      if (result.success) {
        console.log(`✓ ${result.vendor.charAt(0).toUpperCase() + result.vendor.slice(1)} scraping done`);
      } else {
        console.log(`✗ ${result.vendor.charAt(0).toUpperCase() + result.vendor.slice(1)} scraping failed`);
      }
    });
    
    // Show listings from each vendor
    console.log('');
    results.forEach(result => {
      console.log(`[${result.vendor.toUpperCase()}] Found ${result.listings.length} listings`);
      if (result.listings.length > 0) {
        result.listings.forEach((listing, i) => {
          console.log(`  ${i + 1}. $${listing.pricePerMillion}/M (${listing.seller || 'Unknown'})`);
        });
      }
      console.log('');
    });
    
    const allListings = results.flatMap(r => r.listings);
    const lowestPrice = scraperService.calculatePriceIndex(allListings);
    
    console.log('=== LOWEST PRICE ===');
    if (lowestPrice) {
      console.log(`$${lowestPrice}/M`);
    } else {
      console.log('No listings found');
    }
  } catch (error) {
    console.error('Error:', error);
    process.exit(1);
  } finally {
    await scraperService.close();
  }
}

main();
