class ReportsService {

	public PeriodDetails detailsForMonth(long yearMonth) {
		List<Transaction> transactions = new TransactionNormalizer().normalize(transactions(yearMonth));
		Map<String, Long> amountByCategoryName = new HashMap<>();
		for (Transaction transaction : transactions) {
			Category category = transaction.getCategory();
			String categoryName = category == null ? "Uncategorized" : category.getName();
			Long amount = amountByCategoryName.get(categoryName);
			if (amount == null) {
				amount = 0L;
			}
			amountByCategoryName.put(categoryName, amount.longValue() + transaction.getAmount());
		}
		List<CategorySummary> categorySummaries = new ArrayList<>();
		for (Entry<String, Long> entry : amountByCategoryName.entrySet()) {
			categorySummaries.add(new CategorySummary(entry.getKey(), entry.getValue()));
		}
		Collections.sort(categorySummaries, new CategorySummaryAmountDescendingComparator());
		return new PeriodDetails(monthName(yearMonth), categorySummaries);
	}

	@Inject  ReportsService(TransactionsService transactionsService);

}