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

async function createTestUser() {
  try {
    // Hash the password 'password123'
    const hashedPassword = await bcrypt.hash('password123', 10);
    console.log('Generated hash:', hashedPassword);
    
    // Update existing admin user with proper hash
    await db.execute(
      'UPDATE users SET password_hash = ? WHERE email = ?', 
      [hashedPassword, 'admin@school.com']
    );
    
    console.log('Updated admin@school.com with proper password hash');
    
    // Update school user
    await db.execute(
      'UPDATE users SET password_hash = ? WHERE email = ?', 
      [hashedPassword, 'principal@school.com']
    );
    
    console.log('Updated principal@school.com with proper password hash');
    
    // Update parent user  
    await db.execute(
      'UPDATE users SET password_hash = ? WHERE email = ?', 
      [hashedPassword, 'parent@email.com']
    );
    
    console.log('Updated parent@email.com with proper password hash');
    
  } catch (error) {
    console.error('Error:', error.message);
  } finally {
    process.exit();
  }
}

createTestUser();