using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using Tiku.Domain.Identity;

namespace Tiku.IntegrationTests.Api;

internal static class PasswordTestUserExtensions
{
    public const string TestPassword = "passw0rd!123";

    public static User WithTestPassword(this User user)
    {
        user.UserName ??= user.Phone ?? user.Email ?? user.Id.ToString("N");
        user.NormalizedUserName ??= user.UserName.ToUpperInvariant();
        var hasher = new PasswordHasher<User>(Options.Create(new PasswordHasherOptions
        {
            IterationCount = 210_000
        }));
        user.PasswordHash = hasher.HashPassword(user, TestPassword);
        return user;
    }
}
