using FreeSql.DataAnnotations;

namespace BookmarkApi.Data.Entities;

/// <summary>
/// 文件夹实体
/// </summary>
[Table(Name = "folders")]
[Index("idx_folder_user_parent", nameof(UserId) + "," + nameof(ParentId))]
public class Folder
{
    /// <summary>
    /// 文件夹ID
    /// </summary>
    [Column(IsPrimary = true)]
    public Guid Id { get; set; }

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

    /// <summary>
    /// 父文件夹ID（null 为根目录）
    /// </summary>
    public Guid? ParentId { get; set; }

    /// <summary>
    /// 文件夹名称
    /// </summary>
    [Column(IsNullable = false, StringLength = 200)]
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 图标（emoji 或图标名）
    /// </summary>
    [Column(StringLength = 100)]
    public string? Icon { get; set; }

    /// <summary>
    /// 同级排序
    /// </summary>
    [Column(IsNullable = false)]
    public int Order { get; set; }

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

    /// <summary>
    /// 更新时间
    /// </summary>
    [Column(ServerTime = DateTimeKind.Utc)]
    public DateTime UpdatedAt { get; set; }

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

    /// <summary>
    /// 导航属性 - 父文件夹
    /// </summary>
    [Navigate(nameof(ParentId))]
    public virtual Folder? Parent { get; set; }

    /// <summary>
    /// 导航属性 - 子文件夹列表
    /// </summary>
    [Navigate(nameof(ParentId))]
    public virtual List<Folder>? Children { get; set; }

    /// <summary>
    /// 导航属性 - 文件夹内的书签
    /// </summary>
    [Navigate(nameof(Bookmark.FolderId))]
    public virtual List<Bookmark>? Bookmarks { get; set; }
}
