"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var dashboard_wizard_seeds_exports = {};
__export(dashboard_wizard_seeds_exports, {
  wizardGroupSeeder: () => wizardGroupSeeder
});
module.exports = __toCommonJS(dashboard_wizard_seeds_exports);
var import_client = require("@prisma/sql/client");
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
const prisma = new import_client.PrismaClient();
const wizardGroups = [{ id: 1, name: "Static", slug: "static" }];
const dashboardWizardData = JSON.parse(
  import_fs.default.readFileSync(import_path.default.join(__dirname, "json/dashboard-wizard.json"), "utf-8")
);
async function wizardGroupSeeder(company_id) {
  try {
    console.log("\u{1F680} Starting Wizard Group Seeder...");
    for (const wizardGroup of wizardGroups) {
      let existingwizardGroup = await prisma.wizardGroup.findFirst({
        where: { id: wizardGroup.id }
      });
      if (!existingwizardGroup) {
        await prisma.$executeRawUnsafe(`
          SET IDENTITY_INSERT wizard_group ON;
          
          INSERT INTO wizard_group (id, name, slug, company_id)
          VALUES (${wizardGroup.id}, '${wizardGroup.name}', '${wizardGroup.slug}', ${company_id});
        
          SET IDENTITY_INSERT wizard_group OFF;
        `);
        existingwizardGroup = await prisma.wizardGroup.findFirst({
          where: { id: wizardGroup.id }
        });
        console.log(`\u2705 Created wizardGroup: ${existingwizardGroup?.name}`);
      } else {
        console.log(`\u{1F504} wizardGroup with id ${wizardGroup.id} already exists.`);
      }
      for (const dashboardWizard of dashboardWizardData) {
        let existingMasterEntity = await prisma.masterEntity.findFirst({
          where: {
            company_id,
            entity_name: dashboardWizard.entity_name
          }
        });
        if (!existingMasterEntity) {
          await prisma.masterEntity.create({
            data: {
              ...Object.fromEntries(
                Object.entries(dashboardWizard).map(([key, value]) => [
                  key,
                  typeof value === "object" && value !== null ? JSON.stringify(value) : value
                ])
              ),
              company_id,
              entity_name: dashboardWizard.entity_name ?? null,
              entity_type: dashboardWizard.entity_type ?? null,
              dashboard_wizard_group_id: existingwizardGroup?.id,
              name: dashboardWizard.name ?? null
            }
          });
          console.log(
            `\u2705 Created master entity with order no ${dashboardWizard.dashboard_wizard_order_no}`
          );
        } else {
          console.log(
            `\u{1F504} Master entity with name ${dashboardWizard.entity_name} already exists.`
          );
        }
      }
    }
    console.log("\u2705 Wizard Group Seeder completed successfully.");
  } catch (error) {
    console.error(`\u274C Error in wizardGroupSeeder: ${error}`);
    throw error;
  } finally {
    await prisma.$disconnect();
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  wizardGroupSeeder
});
