| | | 1 | | using System.Text; |
| | | 2 | | using RoleRadar.Domain.Notes; |
| | | 3 | | |
| | | 4 | | namespace RoleRadar.Domain.Audit; |
| | | 5 | | |
| | | 6 | | public sealed record AuditContentSummary |
| | | 7 | | { |
| | | 8 | | public const int MaxExcerptChars = 200; |
| | | 9 | | |
| | 1066 | 10 | | public string BodyHash { get; } |
| | | 11 | | |
| | 1066 | 12 | | public int ByteLength { get; } |
| | | 13 | | |
| | 1066 | 14 | | public string Status { get; } |
| | | 15 | | |
| | 1066 | 16 | | public string Excerpt { get; } |
| | | 17 | | |
| | 1570 | 18 | | public AuditContentSummary(string bodyHash, int byteLength, string status, string excerpt) |
| | | 19 | | { |
| | 1570 | 20 | | if (string.IsNullOrWhiteSpace(bodyHash)) |
| | | 21 | | { |
| | 0 | 22 | | throw new ArgumentException("Body hash is required.", nameof(bodyHash)); |
| | | 23 | | } |
| | | 24 | | |
| | 1570 | 25 | | if (byteLength < 0) |
| | | 26 | | { |
| | 0 | 27 | | throw new ArgumentOutOfRangeException(nameof(byteLength), "Byte length cannot be negative."); |
| | | 28 | | } |
| | | 29 | | |
| | 1570 | 30 | | if (string.IsNullOrWhiteSpace(status)) |
| | | 31 | | { |
| | 0 | 32 | | throw new ArgumentException("Status is required.", nameof(status)); |
| | | 33 | | } |
| | | 34 | | |
| | 1570 | 35 | | ArgumentNullException.ThrowIfNull(excerpt); |
| | | 36 | | |
| | 1570 | 37 | | BodyHash = bodyHash; |
| | 1570 | 38 | | ByteLength = byteLength; |
| | 1570 | 39 | | Status = status; |
| | 1570 | 40 | | Excerpt = excerpt.Length <= MaxExcerptChars ? excerpt : excerpt[..MaxExcerptChars]; |
| | 1570 | 41 | | } |
| | | 42 | | |
| | | 43 | | public static AuditContentSummary FromNote(Note note) |
| | | 44 | | { |
| | 1416 | 45 | | ArgumentNullException.ThrowIfNull(note); |
| | 1416 | 46 | | var byteLength = Encoding.UTF8.GetByteCount(note.Body); |
| | 1416 | 47 | | var excerpt = note.Body.Length <= MaxExcerptChars ? note.Body : note.Body[..MaxExcerptChars]; |
| | 1416 | 48 | | return new AuditContentSummary( |
| | 1416 | 49 | | note.CurrentBodyHash, |
| | 1416 | 50 | | byteLength, |
| | 1416 | 51 | | note.Status.ToWireString(), |
| | 1416 | 52 | | excerpt); |
| | | 53 | | } |
| | | 54 | | } |