calculateTotal method
Calculate total cost and summary for all items.
Implementation
DebtSummary calculateTotal(List<DebtItem> items) {
var totalCost = 0.0;
final byType = <DebtType, DebtTypeSummary>{};
final bySeverity = <DebtSeverity, double>{};
for (final item in items) {
final cost = calculateItemCost(item);
totalCost += cost;
// Aggregate by type
final typeSummary = byType[item.type] ??
DebtTypeSummary(type: item.type, count: 0, cost: 0);
byType[item.type] = DebtTypeSummary(
type: item.type,
count: typeSummary.count + 1,
cost: typeSummary.cost + cost,
);
// Aggregate by severity
bySeverity[item.severity] =
(bySeverity[item.severity] ?? 0) + cost;
}
return DebtSummary(
totalCost: totalCost,
costByType: byType,
costBySeverity: bySeverity,
itemCount: items.length,
unit: config.unit,
threshold: config.threshold,
);
}