"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/pg/client");
var import_uuid = require("uuid");
const prisma = new import_client.PrismaClient();
function getCurrentUtcTime() {
  return (/* @__PURE__ */ new Date()).toISOString();
}
async function roleSeeds(company_id) {
  const roles = ["Admin", "Manager", "Supervisor", "Customer", "Support Agent"];
  try {
    let user = await prisma.user.findFirst({
      where: { company_id, role: "super_admin" }
    });
    if (!user) {
      console.log(`Role seeder failed: admin user not available for company id ${company_id}`);
      return false;
    }
    const createdBy = user.id;
    const utcNow = getCurrentUtcTime();
    const existingRoles = await prisma.role.findMany({
      where: { company_id, name: { in: roles } }
    });
    const existingRoleNames = new Set(existingRoles.map((role) => role.name));
    const rolesPromises = [];
    for (let roleName of roles) {
      if (!existingRoleNames.has(roleName)) {
        rolesPromises.push(
          prisma.role.create({
            data: {
              uuid: (0, import_uuid.v4)(),
              name: roleName,
              company_id,
              created_by: createdBy,
              created_at: utcNow
            }
          }).then((role) => {
            console.log(`Role ${role.name} created successfully. id is ${role.id}`);
          }).catch((error) => {
            console.error(`Failed to create role ${roleName} for user_id ${createdBy}:`, error);
          })
        );
      } else {
        console.log(`Role ${roleName} already exists for company_id ${company_id}, skipping creation.`);
      }
    }
    await Promise.all(rolesPromises);
    console.log("Role seeding completed.");
  } catch (error) {
    console.error("Role seeding failed:", error);
  } finally {
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  roleSeeds
});
