import { PrismaClient } from "@prisma/client";
import { hash } from "bcryptjs";

const prisma = new PrismaClient();

async function main() {
  const email = "admin@rima-academy.com";
  const passwordHash = await hash("admin123", 10);

  const existing = await prisma.user.findUnique({ where: { email } });

  if (existing) {
    await prisma.user.update({
      where: { email },
      data: { passwordHash, role: "ADMIN" }
    });
    console.log("Admin updated successfully!");
  } else {
    await prisma.user.create({
      data: {
        email,
        firstName: "Super",
        lastName: "Admin",
        passwordHash,
        role: "ADMIN"
      }
    });
    console.log("Admin created successfully!");
  }
}

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