namespace MeetingAssistant.Speakers; internal static class SpeakerIdentityTranscriptAudit { public static Task AppendIdentifiedAsync( IEnumerable references, string speakerLabel, string name, CancellationToken cancellationToken) { return AppendAsync( references, $"{DateTimeOffset.Now:yyyy-MM-dd} {speakerLabel} was identified as {name}", cancellationToken); } public static Task AppendMergedAsync( IEnumerable references, string name1, string name2, CancellationToken cancellationToken) { return AppendAsync( references, $"{DateTimeOffset.Now:yyyy-MM-dd} {name1} and {name2} were merged", cancellationToken); } private static async Task AppendAsync( IEnumerable references, string line, CancellationToken cancellationToken) { foreach (var transcriptPath in references .Select(reference => reference.TranscriptPath) .Where(path => !string.IsNullOrWhiteSpace(path)) .Distinct(StringComparer.OrdinalIgnoreCase)) { if (!File.Exists(transcriptPath)) { continue; } var existing = await File.ReadAllTextAsync(transcriptPath, cancellationToken); if (existing.Contains(line, StringComparison.OrdinalIgnoreCase)) { continue; } var separator = existing.EndsWith(Environment.NewLine, StringComparison.Ordinal) ? "" : Environment.NewLine; await File.AppendAllTextAsync( transcriptPath, $"{separator}{line}{Environment.NewLine}", cancellationToken); } } }