"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 program_year_seeds_exports = {};
__export(program_year_seeds_exports, {
  financialYearSeeder: () => financialYearSeeder
});
module.exports = __toCommonJS(program_year_seeds_exports);
var import_client = require("@prisma/sql/client");
const prisma = new import_client.PrismaClient();
const entityTypes = [
  {
    name: "2023-2024",
    code: "2023_2024",
    start_date: "2023-04-01",
    end_date: "2024-03-31"
  },
  {
    name: "2024-2025",
    code: "2024_2025",
    start_date: "2024-04-01",
    end_date: "2025-03-31",
    is_freezed: true
  }
];
async function financialYearSeeder(company_id) {
  try {
    console.log("\u{1F680} Starting Financial Year Seeder...");
    const user = await prisma.user.findFirst({
      where: { company_id, role: "super_admin" }
    });
    await prisma.$transaction(async (tx) => {
      for (const entityType of entityTypes) {
        const existingRecord = await tx.financialYear.findFirst({
          where: { company_id, code: entityType.code }
        });
        if (existingRecord) {
          await tx.$executeRawUnsafe(`
            UPDATE financial_years 
            SET name = '${entityType.name}', 
                start_date = '${new Date(entityType.start_date).toISOString()}',
                end_date = '${new Date(entityType.end_date).toISOString()}',
                updated_by = ${user?.id}
            WHERE company_id = ${company_id} AND code = '${entityType.code}';
          `);
          console.log(`\u{1F504} Updated Financial Year with code ${entityType.code}`);
        } else {
          await tx.$executeRawUnsafe(`
            INSERT INTO financial_years (name, code, start_date, end_date, is_freezed, company_id, created_by, updated_by) 
            VALUES (
              '${entityType.name}', 
              '${entityType.code}', 
              '${new Date(entityType.start_date).toISOString()}',
              '${new Date(entityType.end_date).toISOString()}',
              ${entityType.is_freezed ? 1 : 0}, 
              ${company_id}, 
              ${user?.id}, 
              ${user?.id}
            );
          `);
          console.log(`\u2705 Created Financial Year with code ${entityType.code}`);
        }
      }
    });
    console.log("\u2705 Financial Year Seeder completed successfully.");
  } catch (error) {
    console.error(`\u274C Error in financialYearSeeder: ${error}`);
    throw error;
  } finally {
    await prisma.$disconnect();
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  financialYearSeeder
});
