export default async function (
  userid: string,
  context: RequestContext,
  roles?: string[],
): Promise<number> {
  let permissions = 0;

  if (roles?.includes("374851061233614849")) permissions |= 1 << 0; // Administration
  if (!roles) permissions |= 1 << 1;
  if (roles?.includes("593209890949038082")) permissions |= 1 << 2; // Discord Moderator
  if (
    await context.data.prisma.etMember.findUnique({
      select: { id: true },
      where: { id: userid },
    })
  )
    permissions |= 1 << 3; // Events Team
  if (roles?.includes("607594065952899072")) permissions |= 1 << 4; // Events Manager
  if (
    ["165594923586945025", "289372404541554689", "396347223736057866"].includes(
      userid,
    ) ||
    Boolean(await context.env.DATA.get(`gamemod_${userid}`))
  )
    permissions |= 1 << 5;
  if (
    roles?.includes("542750631161626636") ||
    roles?.includes("542750839291248640")
  )
    permissions |= 1 << 6; // Head of Wall Moderation
  if (roles?.includes("684406593214742548")) permissions |= 1 << 7; // Head of Forum Moderation
  if (roles?.includes("784870326990405672")) permissions |= 1 << 8; // Data Team
  if (roles?.includes("298438715380858881")) permissions |= 1 << 9; // Wall Moderator
  if (roles?.includes("681632342346825879")) permissions |= 1 << 10; // Forum Moderator
  if (
    roles?.includes("321710070519955457") ||
    roles?.includes("338102086095077376")
  )
    permissions |= 1 << 11; // Head of Discord Moderation
  if (roles?.includes("409645265700651018")) permissions |= 1 << 12; // Events Coordinator

  return permissions;
}
