// Final manual verification steps
async function finalCheck() {
  console.log('🎯 FINAL DIAGNOSTIC - MANUAL VERIFICATION REQUIRED');
  console.log('='.repeat(60));
  
  try {
    // Get the exact session details
    const sessionResponse = await fetch('http://localhost:3005/api/sessions', {
      headers: { 'X-Api-Key': '992659f827564646ba3ab95ead50adc9' }
    });
    
    if (sessionResponse.ok) {
      const sessions = await sessionResponse.json();
      const defaultSession = sessions.find(s => s.name === 'default');
      
      if (defaultSession) {
        console.log('📱 CURRENT WAHA SESSION:');
        console.log(`   Status: ${defaultSession.status}`);
        console.log(`   Connected as: ${defaultSession.me?.pushName}`);
        console.log(`   Phone: ${defaultSession.me?.id}`);
        console.log(`   Presence: ${defaultSession.presence}`);
        console.log(`   Last activity: ${new Date(defaultSession.timestamps?.activity).toLocaleString()}`);
        
        console.log('\n💡 IMPORTANT QUESTIONS FOR YOU:');
        console.log('='.repeat(40));
        console.log('');
        console.log('1. Is the phone number above YOUR WhatsApp number?');
        console.log(`   Connected number: ${defaultSession.me?.id}`);
        console.log('   If NO: This explains why you don\'t get messages!');
        console.log('');
        console.log('2. Open web.whatsapp.com in your browser RIGHT NOW');
        console.log('   - Is it showing your WhatsApp chats?');
        console.log('   - Or is it asking for QR code?');
        console.log('');
        console.log('3. Check your WhatsApp app on phone:');
        console.log('   - Go to Settings > Linked Devices');
        console.log('   - Is there an active "WhatsApp Web" session?');
        console.log('   - What name does it show?');
        console.log('');
        console.log('4. Try manually sending a message:');
        console.log('   - In web.whatsapp.com, try sending yourself a message');
        console.log('   - Does it work normally?');
        
        // Send one more test with timestamp
        console.log('\n📤 SENDING TIMESTAMPED TEST MESSAGE...');
        const timestamp = new Date().toLocaleString();
        
        const finalTest = {
          session: 'default',
          chatId: defaultSession.me?.id,
          text: `🕐 FINAL TEST - ${timestamp}

This is message #4 sent to you.

Previous messages sent:
1. 3EB0758B5746D26354A59D
2. 3EB0A92BA82BF2E5E405BE  
3. 3EB037402A8FA9766D4AD7
4. This one (ID will be below)

If you don't see ANY of these 4 messages, the issue is NOT with Clinera - it's with WhatsApp Web connection or your phone settings.

Check: web.whatsapp.com`
        };
        
        const finalResponse = await fetch('http://localhost:3005/api/sendText', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'X-Api-Key': '992659f827564646ba3ab95ead50adc9'
          },
          body: JSON.stringify(finalTest)
        });
        
        if (finalResponse.ok) {
          const result = await finalResponse.json();
          console.log(`✅ Final test sent: ${result.key?.id}`);
          console.log(`📱 Timestamp: ${timestamp}`);
        }
        
        console.log('\n🎯 ACTION ITEMS FOR YOU:');
        console.log('='.repeat(30));
        console.log('');
        console.log('1. RIGHT NOW: Open web.whatsapp.com');
        console.log('2. Look for the test messages above');
        console.log('3. If you see them: WAHA is working!');
        console.log('4. If not: WhatsApp Web is disconnected');
        console.log('');
        console.log('🚨 CRITICAL: Tell me what you see at web.whatsapp.com');
        console.log('   - Your chats? Or QR code?');
        console.log('   - Any test messages in your own chat?');
        
        console.log('\n📋 MESSAGE SUMMARY SENT TO YOU:');
        console.log('   All sent to: ' + defaultSession.me?.id);
        console.log('   Total: 4 test messages');
        console.log('   Status: All show "sent" successfully');
        console.log('   Issue: You\'re not receiving them');
        console.log('');
        console.log('🔍 This suggests:');
        console.log('   - Either WhatsApp Web is actually disconnected');
        console.log('   - Or WAHA is connected to wrong WhatsApp account');
        console.log('   - Or your phone/WhatsApp has delivery issues');
      }
    }
    
  } catch (error) {
    console.error('❌ Final check failed:', error);
  }
}

finalCheck().catch(console.error);