import cuid from "cuid";
import { prisma } from "../src/constants";
import { signPermissions } from "../src/modules/permission-utils/signPermissions";

let newRole;
let id = cuid();
const admin = await prisma.role.findFirst({
  where: { moniker: "administrator" },
});

if (admin) console.log("Admin already exists", admin);

if (!admin)
  newRole = await prisma.role.create({
    data: {
      id,
      moniker: "administrator",
      title: "Admin",
      permissions: signPermissions({
        issuer: "roles",
        subject: id,
        permissions: ["*"],
      }),
    },
  });

console.log("Admin Role Created!", newRole);
