"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 email_template_seeds_exports = {};
__export(email_template_seeds_exports, {
  emailTemplatesSeeder: () => emailTemplatesSeeder
});
module.exports = __toCommonJS(email_template_seeds_exports);
var import_client = require("@prisma/sql/client");
var import_uuid = require("uuid");
const prisma = new import_client.PrismaClient();
const datas = [
  {
    slug: "forgot-password",
    name: "Forgot Password",
    subject: "Account Password Reset Request",
    template_body: "<p>Please use the following OTP to reset your password:</p><h2>[otp]</h2> <p>If you didn't request this OTP, please ignore this email.</p>",
    email_template_process_slug: "forgot-password",
    status_id: 1
  },
  {
    slug: "login-otp",
    name: "Login OTP",
    subject: "Your One-Time Password (OTP) for Login Verification",
    template_body: "<p>Please use this OTP to login to your account:</p> <h2>[otp]</h2> <p>If you didn't request this OTP, please ignore this email.</p>",
    email_template_process_slug: "login-otp",
    status_id: 1
  },
  {
    slug: "email-verify",
    name: "Email Verification",
    subject: "Verify Email Address",
    template_body: "<p>Please use the following OTP to verify your email address:</p> <h2>[otp]</h2> <p>If you didn't request this OTP, please ignore this email.</p>",
    email_template_process_slug: "email-verify",
    status_id: 1
  },
  {
    slug: "user-register",
    name: "User Register",
    subject: "New User Registration",
    template_body: "<h1>Welcome aboard!</h1><p>Thank you for registering with us.</p>",
    email_template_process_slug: "user-register",
    status_id: 1
  },
  {
    slug: "user_template_user_created",
    name: "user template - user created",
    subject: "Welcome to LCP",
    template_body: '<p>Hi [user_fullname], </p><p></p><h1 class="ql-align-center">Welcome aboard!</h1><p class="ql-align-center">Thank you for registering with us.</p><p class="ql-align-center">Your user details given below.</p><p class="ql-align-center"></p><ol><li>email : [user_email]</li><li>phone : [user_phone]</li><li>username : [username]</li></ol>',
    email_template_process_slug: "user-created",
    status_id: 1
  },
  {
    slug: "admin_template_user_created",
    name: "admin template - user created",
    subject: "New user created",
    template_body: '<p>Hi Admin,</p><p></p><h1 class="ql-align-center">New user created!</h1><p class="ql-align-center">User details given below.</p><p class="ql-align-center"></p><ol><li>email : [user_email]</li><li>phone : [user_phone]</li><li>username : [username]</li></ol>',
    email_template_process_slug: "user-created",
    status_id: 1
  },
  {
    slug: "department_head_template_user_created",
    name: "department head template - user created",
    subject: "New user created in your Department",
    template_body: '<p>Hi,</p><p></p><h1 class="ql-align-center">New user created in your Department!</h1><p class="ql-align-center">User details given below.</p><p class="ql-align-center"></p><ol><li>email : [user_email]</li><li>phone : [user_phone]</li><li>username : [username]</li></ol>',
    email_template_process_slug: "user-created",
    status_id: 1
  }
];
async function emailTemplatesSeeder(company_id) {
  try {
    console.log("\u{1F680} Starting Email Templates Seeder...");
    const user = await prisma.user.findFirst({
      where: { company_id, role: "super_admin" }
    });
    if (!user) {
      console.log(`\u274C Email Templates Seeder failed: No super_admin user found for company_id ${company_id}`);
      return false;
    }
    const created_by = user.id;
    const templatesToCreate = [];
    for (const data of datas) {
      const emailTemplateProcess = await prisma.emailTemplateProcess.findFirst({
        where: { slug: data.email_template_process_slug, company_id }
      });
      if (!emailTemplateProcess) {
        console.log(`\u26A0\uFE0F Skipping: Email Template Process with slug "${data.email_template_process_slug}" not found for company_id ${company_id}.`);
        continue;
      }
      const existingTemplate = await prisma.emailTemplate.findFirst({
        where: { slug: data.slug, company_id }
      });
      if (!existingTemplate) {
        templatesToCreate.push(
          prisma.emailTemplate.create({
            data: {
              uuid: (0, import_uuid.v4)(),
              slug: data.slug,
              name: data.name,
              subject: data.subject,
              template_body: data.template_body,
              email_template_process_id: emailTemplateProcess.id,
              status_id: data.status_id,
              company_id,
              created_by
            }
          }).then(() => {
            console.log(`\u2705 Created new Email Template: ${data.name} for company_id ${company_id}`);
          }).catch((error) => {
            console.error(`\u274C Error creating email template with slug "${data.slug}":`, error);
          })
        );
      } else {
        console.log(`\u{1F504} Email Template with slug "${data.slug}" already exists for company_id ${company_id}.`);
      }
    }
    await Promise.all(templatesToCreate);
    console.log("\u2705 Email Templates Seeder completed successfully.");
  } catch (error) {
    console.error(`\u274C Error in emailTemplatesSeeder: ${error}`);
    throw error;
  } finally {
    await prisma.$disconnect();
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  emailTemplatesSeeder
});
