using System.Text;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace e_suite.Nuget.PasswordHasher;

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddCustomPasswordHasher(this IServiceCollection services, IConfiguration configuration)
    {
        var authConfigurationSection = configuration.GetSection("AuthConfig");
        var pepper = authConfigurationSection["pepper"];

        services.Configure<CustomPasswordHasherOptions>(options =>
            options.PepperDictionary.Add(1, Encoding.UTF8.GetBytes(pepper!)));

        services.AddTransient<IPasswordHasher<IPassword>, CustomPasswordHasher<IPassword>>();

        return services;
    }
}