import cron from "node-cron";
import { logger } from "../../lib/logger";
import { generateExpensesForCurrentMonth } from "./expenses.service";

export function startExpenseJob(): void {
  cron.schedule("0 1 1 * *", async () => {
    logger.info("Generating monthly expenses...");
    try {
      const results = await generateExpensesForCurrentMonth();
      logger.info({ results }, "Monthly expenses generated");
    } catch (err) {
      logger.error({ err }, "Failed to generate monthly expenses");
    }
  });
  logger.info("Expense cron scheduled: 0 1 1 * *");
}
