using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore; namespace DysonNetwork.Shared.Models; [Index(nameof(Path), nameof(AccountId))] [Index(nameof(ParentFolderId))] public class SnCloudFolder : ModelBase { public Guid Id { get; set; } = Guid.NewGuid(); /// /// The name of the folder /// [MaxLength(256)] public string Name { get; init; } = null!; /// /// The full path of the folder (for querying purposes) /// With trailing slash, e.g., /documents/work/ /// [MaxLength(8192)] public string Path { get; set; } = null!; /// /// Reference to the parent folder (null for root folders) /// public Guid? ParentFolderId { get; set; } /// /// Navigation property to the parent folder /// [ForeignKey(nameof(ParentFolderId))] public SnCloudFolder? ParentFolder { get; init; } /// /// Navigation property to child folders /// [InverseProperty(nameof(ParentFolder))] public List ChildFolders { get; init; } = []; /// /// Navigation property to files in this folder /// [InverseProperty(nameof(SnCloudFileIndex.Folder))] public List Files { get; init; } = []; /// /// The account that owns this folder /// public Guid AccountId { get; init; } /// /// Navigation property to the account /// [NotMapped] public SnAccount? Account { get; init; } /// /// Optional description for the folder /// [MaxLength(4096)] public string? Description { get; init; } /// /// Custom metadata for the folder /// [Column(TypeName = "jsonb")] public Dictionary? FolderMeta { get; init; } /// /// Creates a new folder with proper path normalization /// public static SnCloudFolder Create(string name, Guid accountId, SnCloudFolder? parentFolder = null) { var normalizedPath = parentFolder != null ? $"{parentFolder.Path.TrimEnd('/')}/{name}/" : $"/{name}/"; return new SnCloudFolder { Name = name, Path = normalizedPath, ParentFolderId = parentFolder?.Id, AccountId = accountId }; } /// /// Creates the root folder for an account /// public static SnCloudFolder CreateRoot(Guid accountId) { return new SnCloudFolder { Name = "Root", Path = "/", ParentFolderId = null, AccountId = accountId }; } }