using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Globalization;
namespace Jellyfin.Data.Entities.Security
{
///
/// An entity representing a device.
///
public class Device
{
///
/// Initializes a new instance of the class.
///
/// The user id.
/// The app name.
/// The app version.
/// The device name.
/// The device id.
public Device(Guid userId, string appName, string appVersion, string deviceName, string deviceId)
{
UserId = userId;
AppName = appName;
AppVersion = appVersion;
DeviceName = deviceName;
DeviceId = deviceId;
AccessToken = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
DateCreated = DateTime.UtcNow;
DateModified = DateCreated;
DateLastActivity = DateCreated;
// Non-nullable for EF Core, as this is a required relationship.
User = null!;
}
///
/// Gets the id.
///
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; private set; }
///
/// Gets the user id.
///
public Guid UserId { get; private set; }
///
/// Gets or sets the access token.
///
public string AccessToken { get; set; }
///
/// Gets or sets the app name.
///
[MaxLength(64)]
[StringLength(64)]
public string AppName { get; set; }
///
/// Gets or sets the app version.
///
[MaxLength(32)]
[StringLength(32)]
public string AppVersion { get; set; }
///
/// Gets or sets the device name.
///
[MaxLength(64)]
[StringLength(64)]
public string DeviceName { get; set; }
///
/// Gets or sets the device id.
///
[MaxLength(256)]
[StringLength(256)]
public string DeviceId { get; set; }
///
/// Gets or sets a value indicating whether this device is active.
///
public bool IsActive { get; set; }
///
/// Gets or sets the date created.
///
public DateTime DateCreated { get; set; }
///
/// Gets or sets the date modified.
///
public DateTime DateModified { get; set; }
///
/// Gets or sets the date of last activity.
///
public DateTime DateLastActivity { get; set; }
///
/// Gets the user.
///
public User User { get; private set; }
}
}