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

async function createAdmin() {
  try {
    const hashedPassword = await bcrypt.hash('admin123', 10);

    const [result] = await db.query(
      'INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, ?)',
      ['admin', 'admin@example.com', hashedPassword, 'super_admin']
    );

    console.log('✅ Admin user created successfully!');
    console.log('Email: admin@example.com');
    console.log('Password: admin123');
    process.exit(0);
  } catch (error) {
    if (error.code === 'ER_DUP_ENTRY') {
      console.log('⚠️  Admin user already exists!');
    } else {
      console.error('❌ Error creating admin:', error);
    }
    process.exit(1);
  }
}

createAdmin();
