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

async function checkChildData() {
  try {
    console.log('Checking child data...');
    
    // Check child with ID 51
    const [child51] = await db.execute('SELECT id, first_name, last_name FROM children WHERE id = 51');
    console.log('Child ID 51:', child51[0]);
    if (child51[0]) {
      console.log('first_name:', child51[0].first_name, 'type:', typeof child51[0].first_name);
      console.log('last_name:', child51[0].last_name, 'type:', typeof child51[0].last_name);
    }
    
    // Check all children to see if there are any data type issues
    const [allChildren] = await db.execute('SELECT id, first_name, last_name FROM children LIMIT 10');
    console.log('\nAll children sample:');
    allChildren.forEach(child => {
      console.log(`ID: ${child.id}, first_name: ${child.first_name} (${typeof child.first_name}), last_name: ${child.last_name} (${typeof child.last_name})`);
    });
    
    // Test the name concatenation like in the API
    console.log('\nTesting name concatenation:');
    allChildren.forEach(child => {
      const name = `${child.first_name} ${child.last_name}`;
      console.log(`ID: ${child.id}, concatenated name: ${name} (${typeof name})`);
    });
    
    process.exit(0);
  } catch (error) {
    console.error('Error:', error.message);
    process.exit(1);
  }
}

checkChildData();
