namespace CMSMicroservice.Domain.Entities;
//توکن Otp
public class OtpToken : BaseAuditableEntity
{
    //موبایل مقصد
    public string Mobile { get; set; }
    //مقصود
    public string Purpose { get; set; }
    //کد 
    public string Code { get; set; }
    //کد هش شده
    public string CodeHash { get; set; }
    //زمان انقضا
    public DateTime ExpiresAt { get; set; }
    //شمارش تلاش‌ها
    public int Attempts { get; set; }
    //موفق بود؟
    public bool IsUsed { get; set; }

    /// <summary>
    /// Validates if the provided code is correct and token is not expired
    /// </summary>
    public bool IsValid(string providedCode)
    {
        if (IsUsed || DateTime.UtcNow > ExpiresAt)
            return false;

        // Use BCrypt to verify the provided code against the stored hash
        return BCrypt.Net.BCrypt.Verify(providedCode, CodeHash);
    }
}
