import type { PrismaClient } from "@prisma/client";

const SYSTEM_ROLES: Array<{ code: string; label: string; description: string }> = [
  { code: "admin", label: "Administrator", description: "Full project administration" },
  { code: "me", label: "M&E Lead", description: "Monitoring and evaluation management" },
  { code: "tp", label: "Training Provider", description: "Training provider workspace role" },
  { code: "world_bank", label: "World Bank", description: "Funder read-only role" },
  { code: "edi", label: "EDI", description: "Funder read-only role" },
];

export async function ensureSystemRoles(prisma: PrismaClient): Promise<void> {
  for (const role of SYSTEM_ROLES) {
    await prisma.role.upsert({
      where: { code: role.code },
      create: {
        code: role.code,
        label: role.label,
        description: role.description,
        isSystem: true,
      },
      update: {
        label: role.label,
        description: role.description,
        isSystem: true,
      },
      select: { id: true },
    });
  }
}

