<commit_before>﻿using SFA.DAS.EmployerAccounts.Configuration;
using SFA.DAS.EmployerAccounts.MarkerInterfaces;
using SFA.DAS.HashingService;
using StructureMap;

namespace SFA.DAS.EmployerAccounts.DependencyResolution
{
    public class HashingRegistry : Registry
    {
        public HashingRegistry()
        {
            For<IHashingService>().Use(c => GetHashingService(c));
            For<IPublicHashingService>().Use(c => GetPublicHashingService(c));
            For<IAccountLegalEntityPublicHashingService>().Add(c => GetAccountLegalEntityPublicHashingService(c));
        }

        private IHashingService GetHashingService(IContext context)
        {
            var config = context.GetInstance<EmployerAccountsConfiguration>();
            var hashingService = new HashingService.HashingService(config.AllowedHashstringCharacters, config.Hashstring);

            return hashingService;
        }

        private IPublicHashingService GetPublicHashingService(IContext context)
        {
            var config = context.GetInstance<EmployerAccountsConfiguration>();
            var publicHashingService = new HashingService.HashingService(config.PublicAllowedHashstringCharacters, config.PublicHashstring);

            return publicHashingService as IPublicHashingService;
        }

        private IAccountLegalEntityPublicHashingService GetAccountLegalEntityPublicHashingService(IContext context)
        {
            var config = context.GetInstance<EmployerAccountsConfiguration>();
            var accountLegalEntityPublicHashingService = new HashingService.HashingService(config.PublicAllowedAccountLegalEntityHashstringCharacters, config.PublicAllowedAccountLegalEntityHashstringSalt);

            return accountLegalEntityPublicHashingService as IAccountLegalEntityPublicHashingService;
        }
    }
}<commit_msg>AML-3615: sort out registration of marker interfaces within EmployerAccounts.<commit_after>﻿using System;
using SFA.DAS.EmployerAccounts.Configuration;
using SFA.DAS.EmployerAccounts.MarkerInterfaces;
using SFA.DAS.HashingService;
using StructureMap;

namespace SFA.DAS.EmployerAccounts.DependencyResolution
{
    public class HashingRegistry : Registry
    {
        public HashingRegistry()
        {
            For<IHashingService>()
                .Use(c =>
                    new HashingService.HashingService(
                        c.GetInstance<EmployerAccountsConfiguration>().AllowedHashstringCharacters,
                        c.GetInstance<EmployerAccountsConfiguration>().Hashstring));

            For<IPublicHashingService>()
                .Use<MarkerInterfaceWrapper>()
                .Ctor<IHashingService>()
                .Is(c =>
                     new HashingService.HashingService(
                        c.GetInstance<EmployerAccountsConfiguration>().PublicAllowedHashstringCharacters,
                        c.GetInstance<EmployerAccountsConfiguration>().PublicHashstring)
                );

            For<IAccountLegalEntityPublicHashingService>()
                .Use<MarkerInterfaceWrapper>()
                .Ctor<IHashingService>()
                .Is(c =>
                    new HashingService.HashingService(
                        c.GetInstance<EmployerAccountsConfiguration>() .PublicAllowedAccountLegalEntityHashstringCharacters,
                        c.GetInstance<EmployerAccountsConfiguration>().PublicAllowedAccountLegalEntityHashstringSalt));

        }
    }

    public class MarkerInterfaceWrapper
    : IAccountLegalEntityPublicHashingService,
       IPublicHashingService
    {
        private IHashingService _hashingServiceWithCorrectValuesForMarkerInterface;

        public MarkerInterfaceWrapper(IHashingService hashingServiceWithCorrectValuesForMarkerInterface)
        {
            _hashingServiceWithCorrectValuesForMarkerInterface = hashingServiceWithCorrectValuesForMarkerInterface;
        }

        public string HashValue(long id)
        {
            return _hashingServiceWithCorrectValuesForMarkerInterface.HashValue(id);
        }

        public string HashValue(Guid id)
        {
            return _hashingServiceWithCorrectValuesForMarkerInterface.HashValue(id);
        }

        public string HashValue(string id)
        {
            return _hashingServiceWithCorrectValuesForMarkerInterface.HashValue(id);
        }

        public long DecodeValue(string id)
        {
            return _hashingServiceWithCorrectValuesForMarkerInterface.DecodeValue(id);
        }

        public Guid DecodeValueToGuid(string id)
        {
            return _hashingServiceWithCorrectValuesForMarkerInterface.DecodeValueToGuid(id);
        }

        public string DecodeValueToString(string id)
        {
            return _hashingServiceWithCorrectValuesForMarkerInterface.DecodeValueToString(id);
        }
    }
}
{'fraction_non_alphanumeric': 0.06461601981833195, 'fraction_numerical': 0.0008257638315441783, 'mean_word_length': 2.9009661835748792, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 28, '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': '1919112', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1150, 'n_words': 166}