const db = require('./config/database');

async function testDatabase() {
  try {
    console.log('Testing database connection...\n');

    // Test categories
    const [categories] = await db.query('SELECT * FROM categories');
    console.log('Categories:', categories.length);
    categories.forEach(cat => {
      console.log(`  - ${cat.name} (${cat.slug}) - Status: ${cat.status}`);
    });

    console.log('\n');

    // Test sub_categories
    const [subCategories] = await db.query('SELECT sc.*, c.name as category_name FROM sub_categories sc LEFT JOIN categories c ON sc.category_id = c.id');
    console.log('Sub Categories:', subCategories.length);
    subCategories.forEach(sc => {
      console.log(`  - ${sc.name} (${sc.slug}) - Category: ${sc.category_name} - Status: ${sc.status}`);
    });

    console.log('\n');

    // Test tours
    const [tours] = await db.query('SELECT t.*, sc.name as sub_category_name FROM tours t LEFT JOIN sub_categories sc ON t.sub_category_id = sc.id');
    console.log('Tours:', tours.length);
    tours.forEach(tour => {
      console.log(`  - ${tour.title} - SubCategory: ${tour.sub_category_name} - Status: ${tour.status}`);
    });

    console.log('\n✅ Database test completed!');
    process.exit(0);
  } catch (error) {
    console.error('❌ Database error:', error);
    process.exit(1);
  }
}

testDatabase();
