"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/pg/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"
  },
  {
    name: "2025-2026",
    code: "2025_2026",
    start_date: "2025-04-01",
    end_date: "2026-03-31",
    is_freezed: true
  },
  {
    name: "2026-2027",
    code: "2026_2027",
    start_date: "2026-04-01",
    end_date: "2027-03-31",
    is_freezed: true
  }
];
async function financialYearSeeder(company_id) {
  try {
    const user = await prisma.user.findFirst({
      where: { company_id, role: "super_admin" }
    });
    for (const entityType of entityTypes) {
      await prisma.financialYear.upsert({
        where: { company_id_code: { company_id, code: entityType.code } },
        update: {
          ...entityType,
          updated_by: user?.id,
          start_date: new Date(entityType.start_date).toISOString(),
          end_date: new Date(entityType.end_date).toISOString()
        },
        create: {
          ...entityType,
          company_id,
          created_by: user?.id,
          updated_by: user?.id,
          start_date: new Date(entityType.start_date).toISOString(),
          end_date: new Date(entityType.end_date).toISOString()
        }
      });
      console.log(
        `Updated financialYear with code ${entityType.code}: ${entityType.name}`
      );
    }
  } catch (error) {
    console.error(`Error in financialYearSeeder: ${error}`);
    throw error;
  } finally {
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  financialYearSeeder
});
