| | | 1 | | using RoleRadar.Domain.Common; |
| | | 2 | | |
| | | 3 | | namespace RoleRadar.Domain.Tracking; |
| | | 4 | | |
| | | 5 | | public sealed class SearchRun |
| | | 6 | | { |
| | | 7 | | public const int MaxNotesLength = 500; |
| | | 8 | | |
| | 718 | 9 | | public Guid Id { get; } |
| | 672 | 10 | | public string OwnerId { get; } |
| | 336 | 11 | | public DateTimeOffset StartedAt { get; } |
| | 346 | 12 | | public int NewPostingsCount { get; } |
| | 340 | 13 | | public Guid? ReportNoteId { get; } |
| | 370 | 14 | | public string? Notes { get; } |
| | 362 | 15 | | public DateTimeOffset CreatedAt { get; } |
| | | 16 | | |
| | 352 | 17 | | public SearchRun( |
| | 352 | 18 | | Guid id, |
| | 352 | 19 | | string ownerId, |
| | 352 | 20 | | DateTimeOffset startedAt, |
| | 352 | 21 | | int newPostingsCount, |
| | 352 | 22 | | Guid? reportNoteId, |
| | 352 | 23 | | string? notes, |
| | 352 | 24 | | DateTimeOffset createdAt) |
| | | 25 | | { |
| | 352 | 26 | | if (id == Guid.Empty) |
| | | 27 | | { |
| | 0 | 28 | | throw new ArgumentException("SearchRun id cannot be empty.", nameof(id)); |
| | | 29 | | } |
| | | 30 | | |
| | 352 | 31 | | OwnerId = new OwnerId(ownerId).Value; |
| | 352 | 32 | | StartedAt = startedAt; |
| | 352 | 33 | | if (newPostingsCount < 0) |
| | | 34 | | { |
| | 0 | 35 | | throw new ArgumentOutOfRangeException(nameof(newPostingsCount), "NewPostingsCount must be >= 0."); |
| | | 36 | | } |
| | | 37 | | |
| | 352 | 38 | | NewPostingsCount = newPostingsCount; |
| | 352 | 39 | | ReportNoteId = reportNoteId; |
| | 352 | 40 | | if (notes is not null && notes.Length > MaxNotesLength) |
| | | 41 | | { |
| | 0 | 42 | | throw new ArgumentException($"Notes cannot exceed {MaxNotesLength} characters.", nameof(notes)); |
| | | 43 | | } |
| | | 44 | | |
| | 352 | 45 | | Notes = notes?.Trim(); |
| | 352 | 46 | | CreatedAt = createdAt; |
| | 352 | 47 | | Id = id; |
| | 352 | 48 | | } |
| | | 49 | | |
| | | 50 | | public static SearchRun Create( |
| | | 51 | | string ownerId, |
| | | 52 | | DateTimeOffset startedAt, |
| | | 53 | | int newPostingsCount, |
| | | 54 | | Guid? reportNoteId = null, |
| | | 55 | | string? notes = null, |
| | | 56 | | DateTimeOffset? createdAt = null, |
| | | 57 | | Guid? id = null) |
| | | 58 | | { |
| | 336 | 59 | | return new SearchRun( |
| | 336 | 60 | | id: id ?? Guid.CreateVersion7(), |
| | 336 | 61 | | ownerId: ownerId, |
| | 336 | 62 | | startedAt: startedAt, |
| | 336 | 63 | | newPostingsCount: newPostingsCount, |
| | 336 | 64 | | reportNoteId: reportNoteId, |
| | 336 | 65 | | notes: notes, |
| | 336 | 66 | | createdAt: createdAt ?? DateTimeOffset.UtcNow); |
| | | 67 | | } |
| | | 68 | | } |