const mysql = require('mysql2/promise');

async function checkDatabaseDirectly() {
  try {
    const connection = await mysql.createConnection({
      host: 'localhost',
      user: 'root',
      password: '',
      database: 'cms_db'
    });

    console.log('🔍 Checking database directly...');
    
    // Check if permissions exist
    const [permissions] = await connection.execute(`
      SELECT name FROM permissions 
      WHERE name IN (
        'dashboard.widget.conversations',
        'dashboard.widget.online',
        'dashboard.widget.messages', 
        'dashboard.widget.security',
        'security.view'
      )
    `);
    
    console.log('📋 Found permissions:');
    permissions.forEach(p => console.log(`  ✅ ${p.name}`));
    
    // Check role-permission mappings
    const [mappings] = await connection.execute(`
      SELECT p.name 
      FROM permissions p
      JOIN role_permissions rp ON p.id = rp.permission_id
      WHERE rp.role_id = 1 AND p.name IN (
        'dashboard.widget.conversations',
        'dashboard.widget.online',
        'dashboard.widget.messages',
        'dashboard.widget.security', 
        'security.view'
      )
    `);
    
    console.log('\n🔗 Role-permission mappings:');
    mappings.forEach(m => console.log(`  ✅ ${m.name}`));
    
    await connection.end();
  } catch (error) {
    console.error('❌ Error:', error.message);
  }
}

checkDatabaseDirectly();
