const { Sequelize } = require('sequelize');

const passwords = [
  'password',
  'admin',
  'postgres',
  'root',
  '',
  '123456',
  'postgresql'
];

async function testConnection(password) {
  const sequelize = new Sequelize(
    'luckychit',
    'postgres',
    password,
    {
      host: 'localhost',
      port: 5432,
      dialect: 'postgres',
      logging: false
    }
  );

  try {
    await sequelize.authenticate();
    console.log(`✅ SUCCESS with password: "${password}"`);
    await sequelize.close();
    return password;
  } catch (error) {
    console.log(`❌ Failed with password: "${password}" - ${error.message}`);
    await sequelize.close();
    return null;
  }
}

async function testAllPasswords() {
  console.log('🔍 Testing PostgreSQL passwords...\n');
  
  for (const password of passwords) {
    const result = await testConnection(password);
    if (result) {
      console.log(`\n🎉 Found working password: "${result}"`);
      console.log('💡 Update your .env file with:');
      console.log(`   DB_PASSWORD=${result}`);
      console.log(`   DATABASE_URL=postgresql://postgres:${result}@localhost:5432/luckychit`);
      return result;
    }
  }
  
  console.log('\n❌ No working password found.');
  console.log('💡 Please check your PostgreSQL installation and try:');
  console.log('   1. What password did you set for the postgres user?');
  console.log('   2. Try connecting manually to PostgreSQL');
  console.log('   3. Check if PostgreSQL is running on port 5432');
  
  return null;
}

testAllPasswords();
