"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/pg/client");
var import_fs = __toESM(require("fs"));
const prisma = new import_client.PrismaClient();
const wizardGroups = [{ name: "Static", slug: "static" }];
let wizGroup = {
  static: 0
};
const dashboardWizardData = JSON.parse(
  import_fs.default.readFileSync(__dirname + "/json/dashboard-wizard.json", "utf-8")
);
async function wizardGroupSeeder(company_id) {
  try {
    for (const wizardGroup of wizardGroups) {
      const existingwizardGroup = await prisma.wizardGroup.findUnique({
        where: {
          company_id_slug: {
            company_id,
            slug: wizardGroup.slug
          }
        }
      });
      wizGroup[wizardGroup.slug] = existingwizardGroup?.id ?? 0;
      if (!existingwizardGroup) {
        const createdwizardGroup = await prisma.wizardGroup.create({
          data: {
            name: wizardGroup.name,
            slug: wizardGroup.slug,
            company_id
          }
        });
        console.log(
          `Created wizardGroup with id ${createdwizardGroup.id}: ${createdwizardGroup.name}`
        );
        wizGroup[wizardGroup.slug] = createdwizardGroup?.id ?? 0;
      }
      for (const dashboardWizard of dashboardWizardData) {
        const existingMasterEntity = await prisma.masterEntity.findFirst({
          where: {
            company_id,
            entity_name: dashboardWizard.entity_name
          }
        });
        if (!existingMasterEntity) {
          await prisma.masterEntity.create({
            data: {
              company_id,
              entity_name: dashboardWizard.entity_name,
              entity_type: dashboardWizard.entity_type,
              dashboard_wizard_group_id: wizGroup[dashboardWizard.dashboard_wizard_group_slug || "static"],
              dashboard_wizard_columns: dashboardWizard.dashboard_wizard_columns,
              dashboard_wizard_rows: dashboardWizard.dashboard_wizard_rows,
              dashboard_wizard_type: dashboardWizard.dashboard_wizard_type,
              name: dashboardWizard.name,
              static_page_content: dashboardWizard.static_page_content,
              report_type: dashboardWizard.report_type || "lcp",
              report_information: dashboardWizard.report_information || null,
              dashboard_wizard_order_no: dashboardWizard.dashboard_wizard_order_no,
              dashboard_wizard_options: dashboardWizard.dashboard_wizard_options,
              query_information: dashboardWizard.query_information,
              dashboard_grid: dashboardWizard.dashboard_grid || null,
              status_id: dashboardWizard.status_id || 1
            }
          });
          console.log(
            `Created master entity with order no ${dashboardWizard.dashboard_wizard_order_no}`
          );
        } else {
          await prisma.masterEntity.updateMany({
            where: { entity_name: dashboardWizard.entity_name },
            data: {
              company_id,
              entity_type: dashboardWizard.entity_type,
              dashboard_wizard_group_id: wizGroup[dashboardWizard.dashboard_wizard_group_slug || "static"],
              entity_name: dashboardWizard.entity_name,
              dashboard_wizard_columns: dashboardWizard.dashboard_wizard_columns,
              dashboard_wizard_rows: dashboardWizard.dashboard_wizard_rows,
              dashboard_wizard_type: dashboardWizard.dashboard_wizard_type,
              name: dashboardWizard.name,
              static_page_content: dashboardWizard.static_page_content,
              report_type: dashboardWizard.report_type || "lcp",
              report_information: dashboardWizard.report_information || null,
              dashboard_wizard_order_no: dashboardWizard.dashboard_wizard_order_no,
              dashboard_wizard_options: dashboardWizard.dashboard_wizard_options,
              dashboard_grid: dashboardWizard.dashboard_grid || null,
              query_information: dashboardWizard.query_information,
              status_id: dashboardWizard.status_id || 1
            }
          });
        }
      }
    }
  } catch (error) {
    console.error(`Error in wizardGroupSeeder: ${error}`);
    throw error;
  } finally {
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  wizardGroupSeeder
});
