using Data.SeaHavenIndustries; using SeaHaven.Services.DTOs; namespace SeaHaven.Services.Helpers { public static class WorkOrderCommentProjection { public static WorkOrderCommentDto ToDto( Comments comment, IReadOnlyDictionary? displayNames = null) { return new WorkOrderCommentDto { Id = comment.Id, AuthorId = comment.UserId, AuthorName = ResolveAuthorName(comment, displayNames), Text = comment.Commenttext ?? "", Time = (comment.CreatedDate ?? DateTime.UtcNow).ToUniversalTime().ToString("o"), Documents = comment.Documents }; } public static List ToDtos( IEnumerable comments, IReadOnlyDictionary? displayNames = null) => comments.Select(c => ToDto(c, displayNames)).ToList(); public static IEnumerable CollectAuthorUserIds(IEnumerable comments) => comments .Where(c => !string.IsNullOrWhiteSpace(c.UserId)) .Select(c => c.UserId!) .Distinct(StringComparer.Ordinal); private static string? ResolveAuthorName( Comments comment, IReadOnlyDictionary? displayNames) { if (!string.IsNullOrWhiteSpace(comment.UserId) && displayNames != null && displayNames.TryGetValue(comment.UserId, out var name) && !string.IsNullOrWhiteSpace(name)) { return name; } if (!string.IsNullOrWhiteSpace(comment.Commenter)) return comment.Commenter.Trim(); return null; } } }