namespace FrontOffice.Main.Utilities; /// /// DTO for Network Tree node /// public class NetworkNodeDto { public long UserId { get; set; } public string FullName { get; set; } = string.Empty; public string Mobile { get; set; } = string.Empty; public string? Avatar { get; set; } public string Position { get; set; } = string.Empty; // "Root", "Left" or "Right" public NetworkNodeDto? LeftChild { get; set; } public NetworkNodeDto? RightChild { get; set; } public int Level { get; set; } public bool IsActive { get; set; } = true; public DateTime? JoinedAt { get; set; } public bool IsClubActive { get; set; } public string? ActivationWeekNumber { get; set; } /// /// کد معرف کاربر /// public string? ReferralCode { get; set; } /// /// نام پکیج موثر (مثلاً پکیج طلایی / نقره‌ای) /// public string? PackageName { get; set; } /// آخرین امتیاز پای چپ پکیج طلایی public int GoldLeftLegTotal { get; set; } /// آخرین امتیاز پای راست پکیج طلایی public int GoldRightLegTotal { get; set; } /// آخرین امتیاز پای چپ پکیج نقره‌ای public int SilverLeftLegTotal { get; set; } /// آخرین امتیاز پای راست پکیج نقره‌ای public int SilverRightLegTotal { get; set; } } /// /// DTO for flat node structure (for d3-org-chart) /// public class FlatNetworkNodeDto { public string Id { get; set; } = string.Empty; public string ParentId { get; set; } = string.Empty; public string FullName { get; set; } = string.Empty; public string Mobile { get; set; } = string.Empty; public string? Avatar { get; set; } public string Position { get; set; } = string.Empty; public int Level { get; set; } public bool IsActive { get; set; } = true; public bool IsClubActive { get; set; } public string? ActivationWeekNumber { get; set; } public DateTime? JoinedAt { get; set; } /// /// کد معرف کاربر - فقط برای کاربران فعال در باشگاه نمایش داده شود /// public string? ReferralCode { get; set; } /// /// نام پکیج موثر (مثلاً پکیج طلایی / نقره‌ای) /// public string? PackageName { get; set; } public int GoldLeftLegTotal { get; set; } public int GoldRightLegTotal { get; set; } public int SilverLeftLegTotal { get; set; } public int SilverRightLegTotal { get; set; } } /// /// DTO for Network Tree response /// public class NetworkTreeDto { public NetworkNodeDto? RootNode { get; set; } public int TotalMembers { get; set; } public int CurrentDepth { get; set; } /// /// Convert hierarchical tree to flat array for d3-org-chart /// public List ToFlatArray() { var result = new List(); if (RootNode == null) return result; TraverseAndFlatten(RootNode, "", result); return result; } private void TraverseAndFlatten(NetworkNodeDto node, string parentId, List result) { var flatNode = new FlatNetworkNodeDto { Id = node.UserId.ToString(), ParentId = parentId, FullName = node.FullName, Mobile = node.Mobile, Avatar = node.Avatar, Position = node.Position, Level = node.Level, IsActive = node.IsActive, IsClubActive = node.IsClubActive, ActivationWeekNumber = node.ActivationWeekNumber, JoinedAt = node.JoinedAt, ReferralCode = node.ReferralCode, PackageName = node.PackageName, GoldLeftLegTotal = node.GoldLeftLegTotal, GoldRightLegTotal = node.GoldRightLegTotal, SilverLeftLegTotal = node.SilverLeftLegTotal, SilverRightLegTotal = node.SilverRightLegTotal }; result.Add(flatNode); if (node.LeftChild != null) { TraverseAndFlatten(node.LeftChild, flatNode.Id, result); } if (node.RightChild != null) { TraverseAndFlatten(node.RightChild, flatNode.Id, result); } } } /// /// DTO for Last Member info /// public class LastMemberDto { public long UserId { get; set; } public string FullName { get; set; } = string.Empty; public string Position { get; set; } = string.Empty; public DateTime JoinedAt { get; set; } } /// /// DTO for Network Statistics /// public class NetworkStatisticsDto { public int LeftLegCount { get; set; } public int RightLegCount { get; set; } public int TotalMembers { get; set; } public int TreeDepth { get; set; } public string WeakerLeg { get; set; } = string.Empty; // "Left" or "Right" public LastMemberDto? LastMember { get; set; } }