/**
 * Create staff user 'asim' in Docker database
 */
import { PrismaClient } from './lib/generated/prisma/index.js';
import bcrypt from 'bcryptjs';

const prisma = new PrismaClient();

async function createStaffUser() {
  try {
    console.log('Creating staff user "asim"...\n');

    // Hash the password
    const hashedPassword = await bcrypt.hash('AsimMawidi2025!', 12);

    // Create or update user
    const user = await prisma.user.upsert({
      where: { email: 'asim@mawidi.com' },
      update: {
        username: 'asim',
        password: hashedPassword,
        role: 'SUPER_ADMIN',
      },
      create: {
        id: 'cmhzetlhf0000c90emump3y8c', // Use same ID as local
        email: 'asim@mawidi.com',
        name: 'Asim (Staff)',
        username: 'asim',
        password: hashedPassword,
        role: 'SUPER_ADMIN',
      },
    });

    console.log('✅ Staff user created successfully:');
    console.log({
      id: user.id,
      username: user.username,
      email: user.email,
      role: user.role,
    });
  } catch (error) {
    console.error('❌ Error creating user:', error);
  } finally {
    await prisma.$disconnect();
  }
}

createStaffUser();
