<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SFA.DAS.ProviderRelationships.Api.Client;
using SFA.DAS.ProviderRelationships.Types.Dtos;

namespace SFA.DAS.ProviderApprenticeshipsService.Infrastructure.Services
{
    public class StubProviderRelationshipsApiClient : IProviderRelationshipsApiClient
    {
        private readonly IPublicHashingService _publicHashingService;
        private readonly List<RelationshipDto> _relationships;

        public StubProviderRelationshipsApiClient(IPublicHashingService publicHashingService)
        {
            _publicHashingService = publicHashingService;
            _relationships = new List<RelationshipDto>
            {
                new RelationshipDto
                {
                    Ukprn = 10005077,
                    EmployerAccountId = 1516,
                    EmployerAccountPublicHashedId = _publicHashingService.HashValue(1516),
                    EmployerAccountLegalEntityName = "SAINSBURY'S LIMITED",
                    EmployerAccountLegalEntityId = 353,
                    EmployerAccountLegalEntityPublicHashedId = _publicHashingService.HashValue(353),
                    EmployerAccountName = "SAINSBURY'<NAME>"
                }
            };
        }

        public Task<bool> HasPermission(PermissionRequest request, CancellationToken cancellationToken = new CancellationToken())
        {
            return Task.Run(() => _relationships.Any(r => r.Ukprn == request.Ukprn), cancellationToken);
        }

        public async Task<bool> HasRelationshipWithPermission(RelationshipsRequest request, CancellationToken token)
        {
            return (await GetRelationshipsWithPermission(request, token)).Relationships.Any();
        }

        public Task<RelationshipsResponse> GetRelationshipsWithPermission(RelationshipsRequest request, CancellationToken token)
        {
            return Task.Run(() =>  new RelationshipsResponse { Relationships = _relationships }, token);
        }
    }
}
<commit_msg>Changes stub to derive its faked relationship data from existing apprenticeships<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SFA.DAS.Commitments.Api.Client.Interfaces;
using SFA.DAS.ProviderRelationships.Api.Client;
using SFA.DAS.ProviderRelationships.Types.Dtos;

namespace SFA.DAS.ProviderApprenticeshipsService.Infrastructure.Services
{
    public class StubProviderRelationshipsApiClient : IProviderRelationshipsApiClient
    {
        private readonly IPublicHashingService _publicHashingService;
        private readonly IProviderCommitmentsApi _commitmentsApi;

        public StubProviderRelationshipsApiClient(IPublicHashingService publicHashingService, IProviderCommitmentsApi commitmentsApi)
        {
            _commitmentsApi = commitmentsApi;
            _publicHashingService = publicHashingService;
        }

        private async Task<List<RelationshipDto>> GetStubRelationships()
        {
            var apprenticeships = await  _commitmentsApi.GetProviderApprenticeships(10005077);
            
            var result = new List<RelationshipDto>();
            foreach (var apprenticeship in apprenticeships)
            {

                var relationship = new RelationshipDto
                {
                    EmployerAccountLegalEntityName = apprenticeship.LegalEntityName,
                    EmployerAccountId = apprenticeship.EmployerAccountId,
                    EmployerAccountLegalEntityId =
                        _publicHashingService.DecodeValue(apprenticeship.AccountLegalEntityPublicHashedId),
                    EmployerAccountLegalEntityPublicHashedId = apprenticeship.AccountLegalEntityPublicHashedId,
                    EmployerAccountName = apprenticeship.LegalEntityName + " (Account)",
                    EmployerAccountProviderId = 10005077,
                    EmployerAccountPublicHashedId = _publicHashingService.HashValue(apprenticeship.EmployerAccountId),
                    Ukprn = 10005077
                };

                if (!result.Any(x =>
                    x.EmployerAccountId == relationship.EmployerAccountId && x.EmployerAccountLegalEntityId ==
                    relationship.EmployerAccountLegalEntityId))
                {
                    result.Add(relationship);
                }
            }

            return result;

        }

        public Task<bool> HasPermission(PermissionRequest request, CancellationToken cancellationToken = new CancellationToken())
        {
            return Task.Run(() => GetStubRelationships().Result.Any(r => r.Ukprn == request.Ukprn), cancellationToken);
        }

        public async Task<bool> HasRelationshipWithPermission(RelationshipsRequest request, CancellationToken token)
        {
            return (await GetRelationshipsWithPermission(request, token)).Relationships.Any();
        }

        public Task<RelationshipsResponse> GetRelationshipsWithPermission(RelationshipsRequest request, CancellationToken token)
        {
            return Task.Run(() =>  new RelationshipsResponse { Relationships = GetStubRelationships().Result }, token);
        }
    }
}

{'fraction_non_alphanumeric': 0.0656795747911921, 'fraction_numerical': 0.008731966590736523, 'mean_word_length': 2.697543859649123, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 22, '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': '4560899', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1250, 'n_words': 221}