using Microsoft.AspNetCore.Identity;
using Modules.User.Domain.Gateways;

namespace Modules.User.Application;

public interface IPasswordHasher
{
    public Guid? VerifyPassword(Models.Account? account, string password);
}

public class PasswordHasher : IPasswordHasher, IPasswordGateway
{
    private readonly PasswordHasher<string> _hasher;

    public PasswordHasher()
    {
        _hasher = new();
    }

    public string HashPassword(string password) =>
        _hasher.HashPassword("", password);

    public Guid? VerifyPassword(Models.Account? account, string password)
    {
        if (account == null) return null;
        if (_hasher.VerifyHashedPassword("", account.HashedPassword, password) != PasswordVerificationResult.Failed)
        {
            return account.Id;
        }
        return null;
    }
}