private async Task <IEnumerable <PayeSchemeViewModel> > GetPayeSchemes(AccountDetailViewModel response)
        {
            var result = new List <PayeSchemeViewModel>();

            foreach (var payeScheme in response.PayeSchemes ?? new ResourceList(new List <ResourceViewModel>()))
            {
                var obscured = _payeSchemeObfuscator.ObscurePayeScheme(payeScheme.Id).Replace("/", "%252f");
                var paye     = payeScheme.Id.Replace("/", "%252f");
                _logger.Debug(
                    $"IAccountApiClient.GetResource<PayeSchemeViewModel>(\"{payeScheme.Href.Replace(paye, obscured)}\");");
                try
                {
                    var payeSchemeViewModel = await _accountApiClient.GetResource <PayeSchemeViewModel>(payeScheme.Href);

                    if (IsValidPayeScheme(payeSchemeViewModel))
                    {
                        var item = new PayeSchemeViewModel
                        {
                            Ref          = payeSchemeViewModel.Ref,
                            DasAccountId = payeSchemeViewModel.DasAccountId,
                            AddedDate    = payeSchemeViewModel.AddedDate,
                            RemovedDate  = payeSchemeViewModel.RemovedDate,
                            Name         = payeSchemeViewModel.Name
                        };
                        result.Add(item);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, $"Exception occured in Account API type of {nameof(LegalEntityViewModel)} at  {payeScheme.Href} id {payeScheme.Id}");
                }
            }

            return(result.OrderBy(x => x.Ref));
        }
        public async Task <PayeLevySubmissionsResponse> FindPayeSchemeLevySubmissions(string accountId, string hashedPayeRef)
        {
            var account = await _accountRepository.Get(accountId, AccountFieldsSelection.PayeSchemes);

            if (account == null)
            {
                return(new PayeLevySubmissionsResponse
                {
                    StatusCode = PayeLevySubmissionsResponseCodes.AccountNotFound
                });
            }

            var actualPayeId = _hashingService.DecodeValueToString(hashedPayeRef);

            var selectedPayeScheme = account.PayeSchemes.First(o => o.Ref.Equals(actualPayeId, StringComparison.OrdinalIgnoreCase));

            selectedPayeScheme.Ref = _payeSchemeObfuscator.ObscurePayeScheme(selectedPayeScheme.Ref);

            try
            {
                var levySubmissions = await _levySubmissionsRepository.Get(actualPayeId);

                return(new PayeLevySubmissionsResponse
                {
                    StatusCode = PayeLevySubmissionsResponseCodes.Success,
                    LevySubmissions = levySubmissions ?? new LevyDeclarations(),
                    PayeScheme = selectedPayeScheme
                });
            }
            catch (Exception ex)
            {
                _log.Error(ex, $"Unable to load Levy Declarations for Account Id {accountId} ");


                return(new PayeLevySubmissionsResponse
                {
                    StatusCode = PayeLevySubmissionsResponseCodes.UnexpectedError,
                    PayeScheme = selectedPayeScheme,
                });
            }
        }