export function borrowingDecision(input) { const { active, overdueCount, borrowedCount, limit } = input; if (typeof active !== "boolean") throw new TypeError("active must be boolean"); for (const [name, value] of Object.entries({ overdueCount, borrowedCount, limit })) { if (!Number.isInteger(value) || value < 0) { throw new RangeError(name + " must be a non-negative integer"); } } if (limit < 1) throw new RangeError("limit must be at least 1"); if (!active) return { allowed: false, reason: "INACTIVE" }; if (overdueCount > 0) return { allowed: false, reason: "OVERDUE" }; if (borrowedCount >= limit) return { allowed: false, reason: "AT_LIMIT" }; return { allowed: true, reason: "ELIGIBLE" }; }