using FreeSql.DataAnnotations;

namespace BookmarkApi.Data.Entities;

/// <summary>
/// 书签访问历史实体
/// </summary>
[Table(Name = "bookmark_visits")]
[Index("idx_visit_user_time", nameof(UserId) + "," + nameof(VisitedAt))]
[Index("idx_visit_bookmark", nameof(BookmarkId))]
[Index("idx_visit_device", nameof(DeviceId))]
public class BookmarkVisit
{
    /// <summary>
    /// 记录ID
    /// </summary>
    [Column(IsPrimary = true)]
    public Guid Id { get; set; }

    /// <summary>
    /// 用户ID
    /// </summary>
    [Column(IsNullable = false)]
    public Guid UserId { get; set; }

    /// <summary>
    /// 书签ID
    /// </summary>
    [Column(IsNullable = false)]
    public Guid BookmarkId { get; set; }

    /// <summary>
    /// 访问设备ID
    /// </summary>
    public Guid? DeviceId { get; set; }

    /// <summary>
    /// 访问时间
    /// </summary>
    [Column(ServerTime = DateTimeKind.Utc, CanUpdate = false)]
    public DateTime VisitedAt { get; set; }

    /// <summary>
    /// 导航属性 - 用户
    /// </summary>
    [Navigate(nameof(UserId))]
    public virtual User? User { get; set; }

    /// <summary>
    /// 导航属性 - 书签
    /// </summary>
    [Navigate(nameof(BookmarkId))]
    public virtual Bookmark? Bookmark { get; set; }

    /// <summary>
    /// 导航属性 - 设备
    /// </summary>
    [Navigate(nameof(DeviceId))]
    public virtual Device? Device { get; set; }
}
