"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var role_seeds_exports = {};
__export(role_seeds_exports, {
  roleSeeds: () => roleSeeds
});
module.exports = __toCommonJS(role_seeds_exports);
var import_client = require("@prisma/sql/client");
var import_uuid = require("uuid");
const prisma = new import_client.PrismaClient();
async function roleSeeds(company_id) {
  const roles = ["Admin", "Manager", "Supervisor", "Customer", "Support Agent"];
  try {
    console.log("\u{1F680} Starting Role Seeder...");
    const user = await prisma.user.findFirst({
      where: { company_id, role: "super_admin" }
    });
    if (!user) {
      console.log(`\u274C Role seeder failed: No super_admin user for company_id ${company_id}`);
      return false;
    }
    const createdBy = user.id;
    const utcNow = /* @__PURE__ */ new Date();
    const existingRoles = new Set(
      (await prisma.role.findMany({
        where: { company_id, name: { in: roles } },
        select: { name: true }
      })).map((role) => role.name)
    );
    const rolesToCreate = roles.filter((roleName) => !existingRoles.has(roleName)).map((roleName) => prisma.role.create({
      data: {
        uuid: (0, import_uuid.v4)(),
        name: roleName,
        company_id,
        created_by: createdBy,
        created_at: utcNow
      }
    }).then((role) => {
      console.log(`\u2705 Role ${role.name} created successfully.`);
    }).catch((error) => {
      console.error(`\u274C Failed to create role ${roleName}:`, error);
    }));
    await Promise.all(rolesToCreate);
    console.log("\u2705 Role Seeder completed successfully.");
  } catch (error) {
    console.error("\u274C Role seeding failed:", error);
  } finally {
    await prisma.$disconnect();
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  roleSeeds
});
