"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 app_version_seeds_exports = {};
__export(app_version_seeds_exports, {
  appVersionsSeeder: () => appVersionsSeeder
});
module.exports = __toCommonJS(app_version_seeds_exports);
var import_client = require("@prisma/pg/client");
const prisma = new import_client.PrismaClient();
function getCurrentUtcTime() {
  return (/* @__PURE__ */ new Date()).toISOString();
}
async function appVersionsSeeder(company_id) {
  try {
    const utcNow = getCurrentUtcTime();
    const user = await prisma.user.findFirst({
      where: { company_id, role: "super_admin" }
    });
    if (!user) {
      console.log(
        `App Versions seeder failed: admin user not available for company id ${company_id}`
      );
      return false;
    }
    const appVersions = [{
      type: "app",
      version_type: "major",
      version: "1.0.0",
      description: `<p>1. Released version module under admin-menu -> about LCP and app.</p>  
                    <p>2. Added "app_version_grid" at master entity level.</p>  
                    <p>3. Seeder added for this version.</p>`,
      is_frontend_changed: true,
      is_backend_changed: true,
      is_database_changed: true,
      developed_by: "Mukesh M",
      created_at: /* @__PURE__ */ new Date("2025-03-14 11:33:44.012+05:30")
    }];
    for (const appVersion of appVersions) {
      await createOrUpdateAppVersion(company_id, appVersion, user.id, utcNow);
    }
    console.log("App Versions seeder executed successfully.");
  } catch (error) {
    console.error(`Error in appVersionsSeeder: ${error}`);
    throw error;
  }
}
async function createOrUpdateAppVersion(company_id, appVersion, created_by, utcNow) {
  let existingVersion = await prisma.appversions.findFirst({
    where: {
      company_id,
      type: appVersion.type,
      version_type: appVersion.type,
      version: appVersion.version
    }
  });
  if (!existingVersion) {
    const newVersion = await prisma.appversions.create({
      data: {
        company_id,
        type: appVersion.type,
        version_type: appVersion.version_type,
        version: appVersion.version,
        description: appVersion.description,
        is_frontend_changed: appVersion.is_frontend_changed,
        is_backend_changed: appVersion.is_backend_changed,
        is_database_changed: appVersion.is_database_changed,
        developed_by: appVersion.developed_by,
        created_at: appVersion.created_at,
        created_by
      }
    });
    console.log(`LCP and App version created: ${newVersion.version}`);
  } else {
    await prisma.appversions.update({
      where: { id: existingVersion.id },
      data: {
        description: appVersion.description,
        is_frontend_changed: appVersion.is_frontend_changed,
        is_backend_changed: appVersion.is_backend_changed,
        is_database_changed: appVersion.is_database_changed,
        developed_by: appVersion.developed_by,
        created_at: appVersion.created_at,
        updated_by: created_by,
        updated_at: utcNow
      }
    });
    console.log(`LCP and App version updated: ${existingVersion.version}`);
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  appVersionsSeeder
});
