using FreeSql.DataAnnotations;
using BookmarkApi.Shared.Enums;

namespace BookmarkApi.Data.Entities;

/// <summary>
/// 设备实体
/// </summary>
[Table(Name = "devices")]
[Index("idx_device_user", nameof(UserId))]
[Index("idx_device_user_admin", nameof(UserId) + "," + nameof(IsAdmin))]
public class Device
{
    /// <summary>
    /// 设备ID
    /// </summary>
    [Column(IsPrimary = true)]
    public Guid Id { get; set; }

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

    /// <summary>
    /// 设备名称（用户自定义）
    /// </summary>
    [Column(IsNullable = false, StringLength = 200)]
    public string DeviceName { get; set; } = string.Empty;

    /// <summary>
    /// 设备类型（浏览器类型 + 操作系统）
    /// </summary>
    [Column(IsNullable = false, StringLength = 200)]
    public string DeviceType { get; set; } = string.Empty;

    /// <summary>
    /// 设备指纹（用于识别设备）
    /// </summary>
    [Column(StringLength = 500)]
    public string? DeviceFingerprint { get; set; }

    /// <summary>
    /// 是否为管理员设备
    /// </summary>
    [Column(IsNullable = false)]
    public bool IsAdmin { get; set; }

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

    /// <summary>
    /// 最后活跃时间
    /// </summary>
    [Column(ServerTime = DateTimeKind.Utc)]
    public DateTime LastActiveAt { get; set; }

    /// <summary>
    /// 设备状态
    /// </summary>
    [Column(MapType = typeof(int))]
    public DeviceStatus Status { get; set; } = DeviceStatus.Normal;

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

