"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 languageContent_seeds_exports = {};
__export(languageContent_seeds_exports, {
  languageContentSeeds: () => languageContentSeeds
});
module.exports = __toCommonJS(languageContent_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();
function formatDisplayName(displayName) {
  return displayName.replace(/_/g, " ").toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase());
}
async function languageContent(languageContentData, companyId, languageCode) {
  try {
    console.log(
      `\u{1F680} Processing language content for company ${companyId}, language ${languageCode}`
    );
    const language = await prisma.language.findFirst({
      where: {
        company_id: companyId,
        code: languageCode
      },
      select: {
        id: true
      }
    });
    if (!language) {
      console.log(
        `WARNING: languageContentSeeds: Language with code ${languageCode} does not exist for company id ${companyId}.`
      );
      return;
    }
    const languageId = language.id;
    const displayNames = [
      ...(await prisma.masterEntityLineItem.findMany({
        where: { company_id: companyId, status_id: 1 },
        select: { display_name: true }
      })).map((item) => item.display_name),
      ...(await prisma.menus.findMany({
        where: { company_id: companyId, status_id: 1 },
        select: { name: true }
      })).map((item) => item.name),
      ...(await prisma.menuItems.findMany({
        where: { company_id: companyId, status_id: 1 },
        select: { name: true },
        orderBy: { order_no: "asc" }
      })).map((item) => item.name)
    ];
    const keyValueMapping = {};
    for (const displayName of displayNames) {
      keyValueMapping[displayName] = formatDisplayName(displayName);
    }
    for (const [key, value] of Object.entries(languageContentData)) {
      keyValueMapping[key] = value;
    }
    for (const [key, value] of Object.entries(keyValueMapping)) {
      const existingContent = await prisma.languageContent.findFirst({
        where: {
          language_id: languageId,
          company_id: companyId,
          key_content: key
        }
      });
      if (!existingContent) {
        await prisma.languageContent.create({
          data: {
            language_id: languageId,
            key_content: key,
            values: value,
            company_id: companyId
          }
        });
        console.log(
          `\u2705 Created languageContent: key ${key}, company_id ${companyId}`
        );
      } else {
        console.log(
          `\u{1F504} Skipped existing languageContent: key ${key}, company_id ${companyId}`
        );
      }
    }
  } catch (error) {
    console.error(`\u274C Error in languageContentSeeds: ${error}`);
    if (error instanceof import_client.Prisma.PrismaClientKnownRequestError && error.code === "P2003" && error.meta) {
      console.error(`Foreign key constraint failed: ${error.meta.field_name}`);
    }
    throw error;
  }
}
async function languageContentSeeds(company_id) {
  try {
    console.log("\u{1F680} Starting Language Content Seeder...");
    const languages = [
      { path: "json/language-content-english.json", languageCode: "en-GB" },
      { path: "json/language-content-arabic.json", languageCode: "ar-SA" }
    ];
    for (const { path: filePath, languageCode } of languages) {
      const languageContentList = JSON.parse(
        import_fs.default.readFileSync(import_path.default.join(__dirname, filePath), "utf-8")
      );
      for (const languageContentData of languageContentList) {
        await languageContent(languageContentData, company_id, languageCode);
      }
    }
    console.log("\u2705 Language Content Seeds Completed.");
  } catch (error) {
    console.error(`\u274C Language Content Seeder Failed: ${error}`);
    throw error;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  languageContentSeeds
});
