using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Jellyfin.Data.Enums;
using Jellyfin.Data.Interfaces;
namespace Jellyfin.Data.Entities
{
///
/// An entity representing a preference attached to a user or group.
///
public class Preference : IHasConcurrencyToken
{
///
/// Initializes a new instance of the class.
/// Public constructor with required data.
///
/// The preference kind.
/// The value.
public Preference(PreferenceKind kind, string value)
{
Kind = kind;
Value = value ?? throw new ArgumentNullException(nameof(value));
}
///
/// Initializes a new instance of the class.
/// Default constructor. Protected due to required properties, but present because EF needs it.
///
protected Preference()
{
}
/*************************************************************************
* Properties
*************************************************************************/
///
/// Gets or sets the id of this preference.
///
///
/// Identity, Indexed, Required.
///
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; protected set; }
///
/// Gets or sets the type of this preference.
///
///
/// Required.
///
[Required]
public PreferenceKind Kind { get; protected set; }
///
/// Gets or sets the value of this preference.
///
///
/// Required, Max length = 65535.
///
[Required]
[MaxLength(65535)]
[StringLength(65535)]
public string Value { get; set; }
///
/// Gets or sets the row version.
///
///
/// Required, ConcurrencyToken.
///
[ConcurrencyCheck]
[Required]
public uint RowVersion { get; set; }
///
/// Static create function (for use in LINQ queries, etc.)
///
/// The preference kind.
/// The value.
/// The new instance.
public static Preference Create(PreferenceKind kind, string value)
{
return new Preference(kind, value);
}
///
public void OnSavingChanges()
{
RowVersion++;
}
}
}