using System.Security.Cryptography;

namespace Entity;

/// <summary>
/// 邮件消息实体
/// </summary>
public class EmailMessage : BaseEntity
{
    /// <summary>
    /// 邮件主题
    /// </summary>
    public string Subject { get; set; } = string.Empty;

    /// <summary>
    /// 邮件发送者
    /// </summary>
    public string From { get; set; } = string.Empty;

    /// <summary>
    /// 邮件正文
    /// </summary>
    public string Body { get; set; } = string.Empty;

    /// <summary>
    /// 邮件HTML内容
    /// </summary>
    public string HtmlBody { get; set; } = string.Empty;

    /// <summary>
    /// 邮件接收时间
    /// </summary>
    public DateTime ReceivedDate { get; set; }

    public string To { get; set; } = string.Empty;

    public string Md5 { get; set; } = string.Empty;

    public string ComputeBodyHash()
    {
        using var md5 = MD5.Create();
        var inputBytes = System.Text.Encoding.UTF8.GetBytes(Body + HtmlBody);
        var hashBytes = md5.ComputeHash(inputBytes);
        return Convert.ToHexString(hashBytes);
    }
}
