//-----------------------------------------------------------------------
//
// Copyright (c) aliasvault. All rights reserved.
// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
//
//-----------------------------------------------------------------------
namespace AliasClientDb;
using System.ComponentModel.DataAnnotations;
using AliasClientDb.Abstracts;
///
/// FieldDefinition entity that defines the schema for custom (user-defined) fields.
/// NOTE: System fields (login.username, login.email, etc.) do NOT have FieldDefinition rows.
/// System field metadata is defined in code (SystemFieldRegistry) and is immutable.
/// This table is ONLY for custom fields that users create themselves.
/// Custom fields are always referenced by their GUID (Id), never by FieldKey.
///
public class FieldDefinition : SyncableEntity
{
///
/// Gets or sets the field definition ID.
///
[Key]
public Guid Id { get; set; }
///
/// Gets or sets the field type (Text, Password, Email, URL, Date, etc.).
///
[Required]
[StringLength(50)]
public string FieldType { get; set; } = "Text";
///
/// Gets or sets the display label for the field.
///
[Required]
[StringLength(255)]
public string Label { get; set; } = string.Empty;
///
/// Gets or sets a value indicating whether this field supports multiple values.
///
public bool IsMultiValue { get; set; } = false;
///
/// Gets or sets a value indicating whether the field value is hidden (masked) by default in the UI.
///
public bool IsHidden { get; set; } = false;
///
/// Gets or sets a value indicating whether history tracking is enabled for this field.
///
public bool EnableHistory { get; set; } = false;
///
/// Gets or sets the weight for sorting fields in the UI. This primarily applies to custom fields.
///
public int Weight { get; set; } = 0;
///
/// Gets or sets the applicable item types as JSON array (e.g., '["Login","Identity"]').
/// Null means applicable to all types.
///
public string? ApplicableToTypes { get; set; }
///
/// Gets or sets the field values using this definition.
///
public virtual ICollection FieldValues { get; set; } = [];
///
/// Gets or sets the field history entries using this definition.
///
public virtual ICollection FieldHistories { get; set; } = [];
}