const { DocumentProcessorServiceClient } = require('@google-cloud/documentai');

// Configuration
const PROJECT_ID = 'cim-summarizer';
const LOCATION = 'us';

async function listProcessorTypes() {
  console.log('📋 Listing Document AI Processor Types...\n');
  
  const client = new DocumentProcessorServiceClient();
  
  try {
    console.log(`Searching in: projects/${PROJECT_ID}/locations/${LOCATION}\n`);
    
    const [processorTypes] = await client.listProcessorTypes({
      parent: `projects/${PROJECT_ID}/locations/${LOCATION}`,
    });
    
    console.log(`Found ${processorTypes.length} processor types:\n`);
    
    processorTypes.forEach((processorType, index) => {
      console.log(`${index + 1}. ${processorType.displayName}`);
      console.log(`   Type: ${processorType.name}`);
      console.log(`   Category: ${processorType.category}`);
      console.log(`   Location: ${processorType.location}`);
      console.log(`   Available Locations: ${processorType.availableLocations?.join(', ') || 'N/A'}`);
      console.log(`   Allow Creation: ${processorType.allowCreation}`);
      console.log('');
    });
    
    // Find OCR processor types
    const ocrProcessors = processorTypes.filter(pt => 
      pt.displayName.toLowerCase().includes('ocr') || 
      pt.displayName.toLowerCase().includes('document') ||
      pt.category === 'OCR'
    );
    
    if (ocrProcessors.length > 0) {
      console.log('🎯 Recommended OCR Processors:');
      ocrProcessors.forEach((processor, index) => {
        console.log(`${index + 1}. ${processor.displayName}`);
        console.log(`   Type: ${processor.name}`);
        console.log(`   Category: ${processor.category}`);
        console.log('');
      });
    }
    
    return processorTypes;
    
  } catch (error) {
    console.error('❌ Error listing processor types:', error.message);
    throw error;
  }
}

async function main() {
  try {
    await listProcessorTypes();
  } catch (error) {
    console.error('Failed to list processor types:', error);
    process.exit(1);
  }
}

if (require.main === module) {
  main();
}

module.exports = { listProcessorTypes }; 