"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateCheckRass = calculateCheckRass; const tehran_time_1 = require("./tehran-time"); function calculateCheckRass(checks, baseDate = new Date()) { if (checks.length === 0) { return { checkCount: 0, totalAmount: 0, nearestDueDate: null, farthestDueDate: null, rassDays: 0, rassDate: null, }; } const base = (0, tehran_time_1.tehranCalendarDay)(baseDate); let totalAmount = 0; let weightedDays = 0; const dueDates = []; for (const check of checks) { const due = (0, tehran_time_1.calendarDayOf)(check.dueDate); dueDates.push(due); const days = Math.max(0, (0, tehran_time_1.diffInDays)(base, due)); totalAmount += check.amount; weightedDays += check.amount * days; } const rassDays = totalAmount > 0 ? Math.round(weightedDays / totalAmount) : 0; const rassDate = (0, tehran_time_1.addDays)(base, rassDays); dueDates.sort((a, b) => a.getTime() - b.getTime()); return { checkCount: checks.length, totalAmount, nearestDueDate: dueDates[0]?.toISOString() ?? null, farthestDueDate: dueDates[dueDates.length - 1]?.toISOString() ?? null, rassDays, rassDate: rassDate.toISOString(), }; } //# sourceMappingURL=check-rass.js.map