const bcrypt = require('bcrypt');
const { sequelize } = require('./src/config/database');
const { User } = require('./src/models');

async function createTestUser() {
  try {
    await sequelize.authenticate();
    console.log('✅ Connected to database');

    // Check if user exists
    const existing = await User.findOne({ where: { mobile_number: '9999999999' } });
    
    if (existing) {
      console.log('⚠️  Test user already exists');
      console.log('Mobile: 9999999999');
      console.log('Password: password123');
      return;
    }

    // Create test manager
    const hashedPassword = await bcrypt.hash('password123', 10);
    
    const user = await User.create({
      mobile_number: '9999999999',
      full_name: 'Test Manager',
      password_hash: hashedPassword,
      role: 'manager',
      is_active: true
    });

    console.log('✅ Test user created successfully!');
    console.log('');
    console.log('📱 Login Credentials:');
    console.log('   Mobile: 9999999999');
    console.log('   Password: password123');
    console.log('');
    
    await sequelize.close();
  } catch (error) {
    console.error('❌ Error:', error.message);
  }
}

createTestUser();
