"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 scheduled_job_seeds_exports = {};
__export(scheduled_job_seeds_exports, {
  scheduledJobSeeder: () => scheduledJobSeeder
});
module.exports = __toCommonJS(scheduled_job_seeds_exports);
var import_client = require("@prisma/pg/client");
const prisma = new import_client.PrismaClient();
async function scheduledJobSeeder() {
  try {
    const scheduledJobArr = [
      {
        id: 1,
        cron_url: "api/cron/process-email-jobs",
        timing: "10,30,50 * * * * *",
        concat_base_url: true,
        description: "A scheduled task that processes pending email jobs, sending emails and updating their status accordingly.API Timing: The job runs every minute at the 10th, 30th, and 50th second."
      },
      {
        id: 2,
        cron_url: "api/cron/send-notification-jobs",
        timing: "20,40,59 * * * * *",
        concat_base_url: true,
        description: "Sends queued email or whatsapp jobs such as notifications, alerts, or newsletters.API Timing: The job runs every minute at the 20th, 40th, and 59th second."
      },
      {
        id: 3,
        cron_url: "api/cron/send-notification-jobs?type=email",
        timing: "20,40,59 * * * * *",
        concat_base_url: true,
        description: "Sends queued email jobs such as notifications, alerts, or newsletters. API Timings : Runs Every minute at 20s, 40s, and 59s"
      },
      {
        id: 4,
        cron_url: "api/cron/send-notification-jobs?type=sms",
        timing: "20,40,59 * * * * *",
        concat_base_url: true,
        description: "Sends queued sms jobs such as notifications, alerts, or newsletters. API Timings : Runs Every minute at 20s, 40s, and 59s"
      },
      {
        id: 5,
        cron_url: "api/cron/schedule-import-job",
        timing: "*/2 * * * *",
        concat_base_url: true,
        description: "Schedules and triggers data import jobs from external sources or files. API Timing: The job runs every 2 minutes."
      },
      {
        id: 6,
        cron_url: "api/cron/truncate-request-logs",
        timing: "0 0 */3 * *",
        concat_base_url: true,
        description: "Periodically clears old entries from the request logs to maintain database performance. API Timing: The job runs every 3 days at midnight."
      },
      // every 3 days at midnight
      {
        id: 7,
        cron_url: "api/cron/truncate-audit-logs",
        timing: "0 0 */3 * *",
        concat_base_url: true,
        description: "Periodically clears old entries from the audit logs to manage storage and keep audit data current. API Timing: The job runs every 3 days at midnight."
      },
      // every 3 days at midnight
      {
        id: 8,
        cron_url: "api/cron/process-whatsapp-jobs",
        timing: "10,30,50 * * * * *",
        concat_base_url: true,
        description: "A scheduled task that processes pending whatsapp jobs, sending whatsapp messages and updating their status accordingly. API Timing: The job runs every minute at the 10th, 30th, and 50th second."
      },
      {
        id: 9,
        cron_url: "api/cron/auto-db-backup",
        timing: "0 0 * * 0",
        concat_base_url: true,
        description: "Automatically backs up the database on a weekly basis. API Timing: The job runs every Sunday at midnight."
      }
    ];
    for (const scheduledJob of scheduledJobArr) {
      await findOrCreateScheduledJob(scheduledJob);
    }
    console.log("ScheduledJob creation completed.");
  } catch (error) {
    throw error;
  }
}
async function findOrCreateScheduledJob(scheduledJob) {
  try {
    let resData;
    resData = await prisma.scheduledJob.findUnique({
      where: { id: scheduledJob.id }
    });
    if (!resData) {
      let data = { ...scheduledJob };
      resData = await prisma.scheduledJob.create({ data });
      console.log(
        `ScheduledJob created successfully: ${scheduledJob.cron_url}`
      );
    } else {
      let data = { ...scheduledJob };
      resData = await prisma.scheduledJob.update({
        where: { id: resData.id },
        data
      });
      console.log(`ScheduledJob updated successfully: ${resData.cron_url}`);
    }
    return resData;
  } catch (error) {
    console.log(`ScheduledJob seeder failed: ${scheduledJob.cron_url}`);
    throw error;
  } finally {
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  scheduledJobSeeder
});
