// Quick script to check current database configuration
require('dotenv').config();

console.log('🔍 Current Database Configuration:\n');

// Check if AWS SSM is enabled
const useAwsSsm = process.env.USE_AWS_SSM === 'true' || process.env.USE_AWS_SSM === '1';
console.log(`USE_AWS_SSM: ${useAwsSsm ? '✅ Enabled' : '❌ Disabled'}`);

if (useAwsSsm) {
  console.log('\n📦 AWS SSM Configuration:');
  console.log(`   AWS_REGION: ${process.env.AWS_REGION || 'ap-south-1 (default)'}`);
  console.log(`   AWS_ACCESS_KEY_ID: ${process.env.AWS_ACCESS_KEY_ID ? '✅ Set' : '❌ Not set (using IAM role)'}`);
  console.log(`   AWS_SECRET_ACCESS_KEY: ${process.env.AWS_SECRET_ACCESS_KEY ? '✅ Set' : '❌ Not set (using IAM role)'}`);
  
  const env = process.env.NODE_ENV || 'test';
  const paramPath = (env === 'production' || env === 'prod') 
    ? '/prod/livingai/db/app'
    : '/test/livingai/db/app';
  console.log(`   Parameter Path: ${paramPath}`);
  console.log(`   NODE_ENV: ${env}`);
} else {
  console.log('\n📝 DATABASE_URL Configuration:');
  const dbUrl = process.env.DATABASE_URL;
  if (dbUrl) {
    // Parse and mask the URL for security
    try {
      const url = new URL(dbUrl);
      const maskedUrl = `${url.protocol}//${url.username ? '***' : ''}@${url.hostname}${url.port ? ':' + url.port : ''}${url.pathname}`;
      console.log(`   Connection String: ${maskedUrl}`);
      console.log(`   Host: ${url.hostname}`);
      console.log(`   Port: ${url.port || '5432 (default)'}`);
      console.log(`   Database: ${url.pathname.replace('/', '')}`);
      console.log(`   User: ${url.username || 'Not specified'}`);
    } catch (e) {
      console.log(`   Connection String: ${dbUrl.substring(0, 20)}... (masked)`);
    }
  } else {
    console.log('   ❌ DATABASE_URL not set!');
  }
}

console.log('\n💡 To switch:');
console.log('   - Use AWS SSM: Set USE_AWS_SSM=true');
console.log('   - Use DATABASE_URL: Set USE_AWS_SSM=false or unset it');

