<commit_before>using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SFA.DAS.EAS.Portal.Client.Application.Queries;
using SFA.DAS.EAS.Portal.Client.Services.DasRecruit;
using SFA.DAS.EAS.Portal.Client.Types;
using SFA.DAS.Encoding;
using StructureMap;

namespace SFA.DAS.EAS.Portal.Client
{
    public class PortalClient : IPortalClient
    {
        private readonly IEncodingService _encodingService;
        private readonly IGetAccountQuery _getAccountQuery;
        private readonly IDasRecruitService _dasRecruitService;
        
        public PortalClient(IContainer container, IEncodingService encodingService)
        {
            _encodingService = encodingService;
            _getAccountQuery = container.GetInstance<IGetAccountQuery>();
            _dasRecruitService = container.GetInstance<IDasRecruitService>();
        }
        
        public async Task<Account> GetAccount(string hashedAccountId,
            AccountState accountState, CancellationToken cancellationToken = default)
        {
            var hasPayeScheme = (accountState & AccountState.HasPayeScheme) == AccountState.HasPayeScheme;

            // we potentially map 1 more vacancy than necessary, but it keeps the code clean
            var vacanciesTask = hasPayeScheme ? 
                _dasRecruitService.GetVacancies(hashedAccountId, 2, cancellationToken) : null;

            // might have been better to key doc on the public hashed account id
            var accountId = _encodingService.Decode(hashedAccountId, EncodingType.AccountId);
            var account = await _getAccountQuery.Get(accountId, cancellationToken);

            // at a later date, we might want to create an empty account doc and add the vacancy details to it, but for now, let's keep it simple
            if (!hasPayeScheme || account == null)
                return account;
            
            var vacancies = await vacanciesTask;
            if (vacancies == null)
                return account;
            
            var vacanciesCount = vacancies.Count();
            switch (vacanciesCount)
            {
                case 0:
                    account.VacancyCardinality = Cardinality.None;
                    break;
                case 1:
                    account.VacancyCardinality = Cardinality.One;
                    account.SingleVacancy = vacancies.Single();
                    break;
                default:
                    account.VacancyCardinality = Cardinality.Many;
                    break;
            }

            return account;
        }
    }
}<commit_msg>make code more concise, as per review comment<commit_after>using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SFA.DAS.EAS.Portal.Client.Application.Queries;
using SFA.DAS.EAS.Portal.Client.Services.DasRecruit;
using SFA.DAS.EAS.Portal.Client.Types;
using SFA.DAS.Encoding;
using StructureMap;

namespace SFA.DAS.EAS.Portal.Client
{
    public class PortalClient : IPortalClient
    {
        private readonly IEncodingService _encodingService;
        private readonly IGetAccountQuery _getAccountQuery;
        private readonly IDasRecruitService _dasRecruitService;
        
        public PortalClient(IContainer container, IEncodingService encodingService)
        {
            _encodingService = encodingService;
            _getAccountQuery = container.GetInstance<IGetAccountQuery>();
            _dasRecruitService = container.GetInstance<IDasRecruitService>();
        }
        
        public async Task<Account> GetAccount(string hashedAccountId,
            AccountState accountState, CancellationToken cancellationToken = default)
        {
            var hasPayeScheme = (accountState & AccountState.HasPayeScheme) == AccountState.HasPayeScheme;

            // we potentially map 1 more vacancy than necessary, but it keeps the code clean
            var vacanciesTask = hasPayeScheme ? 
                _dasRecruitService.GetVacancies(hashedAccountId, 2, cancellationToken) : null;

            // might have been better to key doc on the public hashed account id
            var accountId = _encodingService.Decode(hashedAccountId, EncodingType.AccountId);
            var account = await _getAccountQuery.Get(accountId, cancellationToken);

            // at a later date, we might want to create an empty account doc and add the vacancy details to it, but for now, let's keep it simple
            if (!hasPayeScheme || account == null)
                return account;
            
            var vacancies = await vacanciesTask;
            if (vacancies == null)
                return account;
            
            switch (vacancies.Count())
            {
                case 0:
                    account.VacancyCardinality = Cardinality.None;
                    break;
                case 1:
                    account.VacancyCardinality = Cardinality.One;
                    account.SingleVacancy = vacancies.Single();
                    break;
                default:
                    account.VacancyCardinality = Cardinality.Many;
                    break;
            }

            return account;
        }
    }
}
{'fraction_non_alphanumeric': 0.06402614881753509, 'fraction_numerical': 0.0015381657373582003, 'mean_word_length': 2.074468085106383, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264877', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1270, 'n_words': 340}