using CalledIt.DataAccess.Entities;
using Microsoft.AspNetCore.Identity;

namespace CalledIt.Domain.Services;

public sealed class PasswordService : IPasswordService
{
    private readonly PasswordHasher<UserEntity> _passwordHasher = new();

    public string HashPassword(UserEntity user, string password)
    {
        return _passwordHasher.HashPassword(user, password);
    }

    public bool VerifyHashedPassword(UserEntity user, string hashedPassword, string providedPassword)
    {
        var result = _passwordHasher.VerifyHashedPassword(user, hashedPassword, providedPassword);
        return result is PasswordVerificationResult.Success or PasswordVerificationResult.SuccessRehashNeeded;
    }
}
