using Core.Models; namespace Core.Services; /// /// Decides which parsed student notes should be created or updated. /// Unchanged merges are omitted so a re-import does not write history. /// public static class StudentNotesImportPlan { /// /// Builds persist actions from a parse result. Only matches with field changes are included. /// public static IReadOnlyList Create( StudentNotesImportResult parseResult, IReadOnlySet studentIdsWithExistingNotes) { ArgumentNullException.ThrowIfNull(parseResult); ArgumentNullException.ThrowIfNull(studentIdsWithExistingNotes); List actions = []; foreach (var match in parseResult.Matches) { if (!match.Merge.Changed) continue; actions.Add(new StudentNotePersistAction { StudentId = match.Student.Id, Markdown = match.Merge.Markdown, Kind = studentIdsWithExistingNotes.Contains(match.Student.Id) ? StudentNotePersistKind.Update : StudentNotePersistKind.Create }); } return actions; } } public enum StudentNotePersistKind { Create, Update } public class StudentNotePersistAction { public required int StudentId { get; init; } public required string Markdown { get; init; } public required StudentNotePersistKind Kind { get; init; } }