"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 approval_workflow_approver_tag_seed_exports = {};
__export(approval_workflow_approver_tag_seed_exports, {
  approvalWorkflowApproverTag: () => approvalWorkflowApproverTag
});
module.exports = __toCommonJS(approval_workflow_approver_tag_seed_exports);
var import_client = require("@prisma/pg/client");
const prisma = new import_client.PrismaClient();
function getCurrentUtcTime() {
  return (/* @__PURE__ */ new Date()).toISOString();
}
async function approvalWorkflowApproverTag(company_id) {
  console.log("Seeding ApprovalWorkflowApproverTag...");
  let user = await prisma.user.findFirst({
    where: { company_id, role: "super_admin" }
  });
  if (!user) {
    console.log(`Department seeder failed: admin user not available for company id ${company_id}`);
    return false;
  }
  const createdBy = user.id;
  const utcNow = getCurrentUtcTime();
  const approverTags = [
    {
      slug: "department_head",
      name: "Department Head",
      description: "Approver is the head of the department",
      query_information: `SELECT dh.user_id from user_details as ud 
                          INNER JOIN departments as d ON d.id = ud.department_id
                          INNER JOIN user_details as dh ON dh.id = d.department_head_id
                          WHERE ud.user_id = $session_user_id;`,
      company_id,
      created_by: createdBy,
      updated_by: createdBy,
      created_at: utcNow,
      updated_at: utcNow
    },
    {
      slug: "requested_user",
      name: "Requested User",
      description: "Approver is the user who made the request",
      query_information: `SELECT * FROM users WHERE id = $session_user_id`,
      company_id,
      created_by: createdBy,
      updated_by: createdBy,
      created_at: utcNow,
      updated_at: utcNow
    },
    {
      slug: "finance_manager",
      name: "Finance Manager",
      description: "Approver is the finance department head",
      query_information: `SELECT u.* FROM users AS u 
                          WHERE u.role_id = (SELECT id FROM roles WHERE name = 'Admin')`,
      company_id,
      created_by: createdBy,
      updated_by: createdBy,
      created_at: utcNow,
      updated_at: utcNow
    }
  ];
  for (const tag of approverTags) {
    await prisma.approvalWorkflowApproverTag.upsert({
      where: { company_id_slug: { company_id, slug: tag.slug } },
      update: tag,
      create: tag
    });
  }
  console.log("Seeding completed!");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  approvalWorkflowApproverTag
});
