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

async function fixPrincipalPassword() {
  try {
    const hashedPassword = await bcrypt.hash('111', 10);
    
    // Update principal@school.com password
    await db.execute(
      'UPDATE users SET password_hash = ? WHERE email = ? AND user_type = ?',
      [hashedPassword, 'principal@school.com', 'school']
    );
    
    console.log('Updated password for principal@school.com to "111"');
    
    // Verify
    const [rows] = await db.execute('SELECT password_hash FROM users WHERE email = ?', ['principal@school.com']);
    const isValid = await bcrypt.compare('111', rows[0].password_hash);
    console.log(`principal@school.com: password "111" valid = ${isValid}`);
    
    process.exit(0);
  } catch (error) {
    console.error('Error:', error);
    process.exit(1);
  }
}

fixPrincipalPassword();