import { PrismaClient } from '@prisma/client'
import bcrypt from 'bcryptjs'

const prisma = new PrismaClient()

async function main() {
  const password = await bcrypt.hash('admin123', 10)
  const user = await prisma.user.upsert({
    where: { username: 'admin' },
    update: { password }, // update password if already exists
    create: {
      username: 'admin',
      password,
    },
  })
  console.log('Admin user created:', user.username)
}

main()
  .then(async () => {
    await prisma.$disconnect()
  })
  .catch(async (e) => {
    console.error(e)
    await prisma.$disconnect()
    process.exit(1)
  })
