public async Task <IResponseContainerWithValue <IReadOnlyList <ConnectorCreationSuggestion> > > AllocateAsync(int chargeStationId, decimal maxCurrentInAmps) { IResponseContainerWithValue <IReadOnlyList <ConnectorCreationSuggestion> > result; var group = await groupRepository.GetByChargeStationIdAsync(chargeStationId); var createConnectorSuggestions = new List <ConnectorCreationSuggestion>(); if (group.CapacityInAmps < maxCurrentInAmps) { result = new ResponseContainerWithValue <IReadOnlyList <ConnectorCreationSuggestion> >(); result.AddErrorMessage($"Max current {maxCurrentInAmps} provided exceeds group's {group.Name} capacity."); return(result); } var occupiedCapacity = group.GetOccupiedCapacity(); if (!group.WillBecomeOvercapped(occupiedCapacity, maxCurrentInAmps)) { return new ResponseContainerWithValue <IReadOnlyList <ConnectorCreationSuggestion> > { Value = createConnectorSuggestions } } ; var connectors = await connectorRepository.GetAllInGroupByChargeStationIdAsync(chargeStationId); var suggestions = GetUniqueSuggestions(group, connectors, occupiedCapacity, maxCurrentInAmps); var suggestionCombinations = GetIndexesCombinations(suggestions, connectors); suggestions.AddRange(suggestionCombinations); if (!suggestions.Any()) { result = new ResponseContainerWithValue <IReadOnlyList <ConnectorCreationSuggestion> >(); result.AddErrorMessage($"No suggestion could be made to free exact amount of space for the {nameof(chargeStationId)}={chargeStationId} and {nameof(maxCurrentInAmps)}={maxCurrentInAmps}."); } else { createConnectorSuggestions.AddRange(suggestions.Select(s => Suggestion.ToConnectorCreationSuggestion(s, connectors))); result = new ResponseContainerWithValue <IReadOnlyList <ConnectorCreationSuggestion> > { Value = createConnectorSuggestions }; } return(result); }