using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json.Serialization; using DysonNetwork.Common.Models; using NodaTime; using AccountConnection = DysonNetwork.Common.Models.AccountConnection; namespace DysonNetwork.Pass.Features.Auth.Models; [Index(nameof(Email), IsUnique = true)] public class Account : ModelBase { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } [Required] [MaxLength(256)] public string Email { get; set; } = string.Empty; [Required] [MaxLength(256)] public string Name { get; set; } = string.Empty; [MaxLength(32)] public string? Status { get; set; } [Required] public Instant CreatedAt { get; set; } = SystemClock.Instance.GetCurrentInstant(); [Required] public Instant UpdatedAt { get; set; } = SystemClock.Instance.GetCurrentInstant(); // Navigation properties [JsonIgnore] public virtual ICollection Sessions { get; set; } = new List(); [JsonIgnore] public virtual ICollection Challenges { get; set; } = new List(); [JsonIgnore] public virtual ICollection AuthFactors { get; set; } = new List(); [JsonIgnore] public virtual ICollection Connections { get; set; } = new List(); public void UpdateTimestamp() { UpdatedAt = SystemClock.Instance.GetCurrentInstant(); } public static Account FromCommonModel(DysonNetwork.Common.Models.Account commonAccount) { return new Account { Id = Guid.Parse(commonAccount.Id), Email = commonAccount.Profile?.Email ?? string.Empty, Name = commonAccount.Name, Status = commonAccount.Status, CreatedAt = commonAccount.CreatedAt, UpdatedAt = commonAccount.UpdatedAt }; } public DysonNetwork.Common.Models.Account ToCommonModel() { return new DysonNetwork.Common.Models.Account { Id = Id.ToString(), Name = Name, Status = Status, CreatedAt = CreatedAt, UpdatedAt = UpdatedAt, Profile = new DysonNetwork.Common.Models.Profile { Email = Email, DisplayName = Name } }; } }