public async Task <Dictionary <string, AccountBalanceChangeContract[]> > ByAccount(
            string accountId,
            [FromQuery] DateTime? @from = null,
            [FromQuery] DateTime?to     = null,
            [FromQuery] AccountBalanceChangeReasonTypeContract?reasonType = null,
            [FromQuery] bool filterByTradingDay = false)
        {
            var data = await _accountBalanceChangesRepository.GetAsync(
                accountId,
                @from?.AssumeUtcIfUnspecified(),
                to?.AssumeUtcIfUnspecified(),
                reasonType?.ToType <AccountBalanceChangeReasonType>(),
                filterByTradingDay);

            return(data.GroupBy(i => i.AccountId).ToDictionary(g => g.Key, g => g.Select(Convert).ToArray()));
        }
        /// <summary>
        /// Validate accounts for deletion.
        /// </summary>
        /// <param name="accountIdsToValidate">Accounts to validate.</param>
        /// <returns>Dictionary of failed accountIds with fail reason.</returns>
        private async Task <Dictionary <string, string> > ValidateAccountsAsync(
            IEnumerable <string> accountIdsToValidate)
        {
            var failedAccounts = new Dictionary <string, string>();

            foreach (var accountId in accountIdsToValidate)
            {
                var account = await _accountsRepository.GetAsync(accountId);

                if (account == null)
                {
                    failedAccounts.Add(accountId, $"Account [{accountId}] does not exist");
                    continue;
                }

                if (account.IsDeleted)
                {
                    failedAccounts.Add(accountId, $"Account [{accountId}] is deleted. No operations are permitted.");
                    continue;
                }

                if (account.Balance != 0)
                {
                    failedAccounts.Add(accountId,
                                       $"Account [{accountId}] balance is non-zero, so it cannot be deleted.");
                    continue;
                }

                var todayTransactions = await _accountBalanceChangesRepository.GetAsync(accountId,
                                                                                        _systemClock.UtcNow.UtcDateTime.Date);

                if (todayTransactions.Any())
                {
                    failedAccounts.Add(accountId, $"Account [{accountId}] had {todayTransactions.Count} transactions today. Please try to delete an account tomorrow.");
                    continue;
                }
            }

            return(failedAccounts);
        }