const { PrismaClient } = require('@prisma/client');
const bcrypt = require('bcryptjs');

const prisma = new PrismaClient();

async function main() {
  const adminEmail = 'admin@indianbooksworldwide.com';
  const customerEmail = 'customer@indianbooksworldwide.com';
  const plainPassword = 'Password@123';

  // Hash password
  const passwordHash = await bcrypt.hash(plainPassword, 12);

  // Upsert Admin
  const admin = await prisma.admin.upsert({
    where: { email: adminEmail },
    create: {
      email: adminEmail,
      password: passwordHash,
      name: 'Vedic Admin',
      role: 'ADMIN',
      permissions: { catalog: true, imports: true, orders: true }
    },
    update: {
      password: passwordHash,
      name: 'Vedic Admin'
    }
  });
  console.log('Demo Admin seeded:', admin);

  // Upsert Customer User
  const user = await prisma.user.upsert({
    where: { email: customerEmail },
    create: {
      email: customerEmail,
      password: passwordHash,
      firstName: 'Aarav',
      lastName: 'Sharma',
      phone: '9876543210',
      status: 'ACTIVE',
      isEmailVerified: true
    },
    update: {
      password: passwordHash,
      firstName: 'Aarav',
      lastName: 'Sharma',
      status: 'ACTIVE',
      isEmailVerified: true
    }
  });
  console.log('Demo Customer User seeded:', user);
}

main()
  .catch(console.error)
  .finally(() => prisma.$disconnect());
