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

async function fixAdminUser() {
  try {
    const adminPassword = await bcrypt.hash('admin123', 10);
    
    await db.execute(`
      INSERT INTO users (id, username, email, password_hash, first_name, last_name, user_type, phone) 
      VALUES (101, 'superadmin', 'admin@gpstracking.com', ?, 'Super', 'Admin', 'admin', '555-0124')
      ON DUPLICATE KEY UPDATE 
      password_hash = VALUES(password_hash),
      user_type = 'admin'
    `, [adminPassword]);
    
    console.log('✓ Admin user fixed: admin@gpstracking.com / admin123');
    
  } catch (error) {
    console.error('Error:', error);
  } finally {
    process.exit();
  }
}

fixAdminUser();