"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 language_seeds_exports = {};
__export(language_seeds_exports, {
  languageSeeds: () => languageSeeds
});
module.exports = __toCommonJS(language_seeds_exports);
var import_client = require("@prisma/pg/client");
var import_uuid = require("uuid");
const prisma = new import_client.PrismaClient();
async function languageSeeds(companyId) {
  try {
    let user = await prisma.user.findFirst({
      where: { company_id: companyId, role: "super_admin" }
    });
    if (!user) {
      console.log(`Menu seeder failed: admin user not available for company id ${companyId}`);
      return false;
    }
    const createdBy = user.id;
    const langList = [
      {
        "name": "English",
        "code": "en-GB",
        "status": 1
      },
      {
        "name": "Arabic",
        "code": "ar-QA",
        "status": 1
      },
      {
        "name": "French",
        "code": "fr-FR",
        "status": 3
      },
      {
        "name": "German",
        "code": "de-DE",
        "status": 3
      }
    ];
    const company = await prisma.user.findFirst({
      where: { company_id: companyId }
    });
    if (!company) {
      console.log(`WARNING: languageSeeds: Company with id ${companyId} does not exist.`);
      return;
    }
    for (const { name, code, status } of langList) {
      const existingRecord = await prisma.language.findFirst({
        where: {
          name,
          company_id: companyId
        }
      });
      if (existingRecord) {
        console.log(`Language "${name}" already inserted for company_id ${companyId}`);
      } else {
        await prisma.language.create({
          data: {
            uuid: (0, import_uuid.v4)(),
            name,
            name_in_english: name,
            code,
            description: name,
            status_id: status,
            company_id: companyId,
            created_by: createdBy
          }
        });
        console.log(`Created new language: name ${name}, company_id ${companyId}`);
      }
    }
  } catch (error) {
    console.error(`Error in languageSeeds: ${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;
  } finally {
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  languageSeeds
});
