| | | 1 | | namespace RoleRadar.Domain.Notes; |
| | | 2 | | |
| | | 3 | | public sealed record NoteImportMetadata |
| | | 4 | | { |
| | 1832 | 5 | | public string ImportKey { get; } |
| | | 6 | | |
| | 814 | 7 | | public string SourceFileId { get; } |
| | | 8 | | |
| | 812 | 9 | | public string HeadingPath { get; } |
| | | 10 | | |
| | 810 | 11 | | public int OccurrenceIndex { get; } |
| | | 12 | | |
| | 1194 | 13 | | public int SectionOrderIndex { get; } |
| | | 14 | | |
| | 1836 | 15 | | public string LastImportedBodyHash { get; } |
| | | 16 | | |
| | 1644 | 17 | | private NoteImportMetadata( |
| | 1644 | 18 | | string importKey, |
| | 1644 | 19 | | string sourceFileId, |
| | 1644 | 20 | | string headingPath, |
| | 1644 | 21 | | int occurrenceIndex, |
| | 1644 | 22 | | int sectionOrderIndex, |
| | 1644 | 23 | | string lastImportedBodyHash) |
| | | 24 | | { |
| | 1644 | 25 | | ImportKey = importKey; |
| | 1644 | 26 | | SourceFileId = sourceFileId; |
| | 1644 | 27 | | HeadingPath = headingPath; |
| | 1644 | 28 | | OccurrenceIndex = occurrenceIndex; |
| | 1644 | 29 | | SectionOrderIndex = sectionOrderIndex; |
| | 1644 | 30 | | LastImportedBodyHash = lastImportedBodyHash; |
| | 1644 | 31 | | } |
| | | 32 | | |
| | | 33 | | public static NoteImportMetadata Create( |
| | | 34 | | string sourceFileId, |
| | | 35 | | string headingPath, |
| | | 36 | | int occurrenceIndex, |
| | | 37 | | int sectionOrderIndex, |
| | | 38 | | string lastImportedBodyHash) |
| | | 39 | | { |
| | 822 | 40 | | if (string.IsNullOrWhiteSpace(sourceFileId)) |
| | | 41 | | { |
| | 0 | 42 | | throw new ArgumentException("Source file identifier is required.", nameof(sourceFileId)); |
| | | 43 | | } |
| | | 44 | | |
| | 822 | 45 | | if (string.IsNullOrWhiteSpace(headingPath)) |
| | | 46 | | { |
| | 0 | 47 | | throw new ArgumentException("Heading path is required.", nameof(headingPath)); |
| | | 48 | | } |
| | | 49 | | |
| | 822 | 50 | | if (occurrenceIndex < 0) |
| | | 51 | | { |
| | 0 | 52 | | throw new ArgumentOutOfRangeException(nameof(occurrenceIndex), "Occurrence index cannot be negative."); |
| | | 53 | | } |
| | | 54 | | |
| | 822 | 55 | | if (sectionOrderIndex < 0) |
| | | 56 | | { |
| | 0 | 57 | | throw new ArgumentOutOfRangeException(nameof(sectionOrderIndex), "Section order index cannot be negative."); |
| | | 58 | | } |
| | | 59 | | |
| | 822 | 60 | | if (string.IsNullOrWhiteSpace(lastImportedBodyHash) || lastImportedBodyHash.Length != 64) |
| | | 61 | | { |
| | 0 | 62 | | throw new ArgumentException("Last-imported body hash must be a 64-character lowercase hex SHA-256 string.", |
| | | 63 | | } |
| | | 64 | | |
| | 822 | 65 | | var normalizedSourceId = sourceFileId.Trim(); |
| | 822 | 66 | | var normalizedHeadingPath = headingPath.Trim(); |
| | 822 | 67 | | var importKey = $"{normalizedSourceId}#{normalizedHeadingPath}#{occurrenceIndex}"; |
| | | 68 | | |
| | 822 | 69 | | return new NoteImportMetadata( |
| | 822 | 70 | | importKey, |
| | 822 | 71 | | normalizedSourceId, |
| | 822 | 72 | | normalizedHeadingPath, |
| | 822 | 73 | | occurrenceIndex, |
| | 822 | 74 | | sectionOrderIndex, |
| | 822 | 75 | | lastImportedBodyHash.ToLowerInvariant()); |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | public static NoteImportMetadata Rehydrate( |
| | | 79 | | string importKey, |
| | | 80 | | string sourceFileId, |
| | | 81 | | string headingPath, |
| | | 82 | | int occurrenceIndex, |
| | | 83 | | int sectionOrderIndex, |
| | | 84 | | string lastImportedBodyHash) => |
| | 822 | 85 | | new(importKey, sourceFileId, headingPath, occurrenceIndex, sectionOrderIndex, lastImportedBodyHash); |
| | | 86 | | |
| | | 87 | | public NoteImportMetadata WithUpdatedImportState(int sectionOrderIndex, string newImportedBodyHash) => |
| | 8 | 88 | | Create(SourceFileId, HeadingPath, OccurrenceIndex, sectionOrderIndex, newImportedBodyHash); |
| | | 89 | | } |