"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 device_registration_seeds_exports = {};
__export(device_registration_seeds_exports, {
  deviceRegistrationSeeder: () => deviceRegistrationSeeder
});
module.exports = __toCommonJS(device_registration_seeds_exports);
var import_client = require("@prisma/pg/client");
const prisma = new import_client.PrismaClient();
function getCurrentUtcTime() {
  return (/* @__PURE__ */ new Date()).toISOString();
}
async function deviceRegistrationSeeder(company_id) {
  try {
    let user = await prisma.user.findFirst({
      where: { company_id, role: "super_admin" }
    });
    if (!user) {
      console.log(
        `Role seeder failed: admin user not available for company id ${company_id}`
      );
      return false;
    }
    const createdBy = user.id;
    const utcNow = getCurrentUtcTime();
    const sampleDeviceRegistration = {
      id: 1,
      // Ensure this ID does not conflict with existing IDs
      company_id,
      // Use the passed company_id
      device_name: "Sample Device",
      device_unique_id: "unique-id-5678",
      user_id: 1,
      // Replace with an actual user ID that exists in your database
      status_id: 1,
      // Assuming this corresponds to a valid status ID
      created_by: createdBy,
      created_at: utcNow,
      updated_by: null,
      // Initially, this can be null
      updated_at: null,
      // Initially, this can be null
      deleted_by: null,
      // Initially, this can be null
      deleted_at: null
      // Initially, this can be null
    };
    const deviceRegistration = await prisma.deviceRegistration.upsert({
      where: {
        id: sampleDeviceRegistration.id
        // Identify existing record by ID
      },
      update: {
        // Fields to update if a matching record is found
        device_name: sampleDeviceRegistration.device_name,
        device_unique_id: sampleDeviceRegistration.device_unique_id,
        user_id: sampleDeviceRegistration.user_id,
        status_id: sampleDeviceRegistration.status_id,
        updated_by: createdBy,
        updated_at: utcNow
      },
      create: {
        // Fields to create if no matching record is found
        ...sampleDeviceRegistration,
        updated_at: utcNow,
        // Set updated_at to current time during creation
        updated_by: createdBy,
        // Set updated_by to the creator
        deleted_by: null,
        // Can stay null
        deleted_at: null
        // Can stay null
      }
    });
    console.log("Device Registration Created or Updated:", deviceRegistration);
    return true;
  } catch (error) {
    console.error(`Error in deviceRegistrationSeeder: ${error}`);
    throw error;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  deviceRegistrationSeeder
});
