using System.Text.Json; namespace VideoDownloader.Browser; public sealed record NoteItem(string Id, string Title, string Body, DateTime CreatedAt); /// T3-12: 노트 패널 저장소 — 마크다운 텍스트 노트 추가·검색·삭제, JSON 영속. public sealed class NotesStore { private readonly string _path; private readonly object _gate = new(); private List _items; public NotesStore(string path) { _path = path; try { if (File.Exists(path)) _items = JsonSerializer.Deserialize>(File.ReadAllText(path)) ?? new(); } catch { } _items ??= new List(); } public string Add(string title, string body) { var note = new NoteItem(Guid.NewGuid().ToString("N"), title, body, DateTime.Now); lock (_gate) { _items.Insert(0, note); try { Directory.CreateDirectory(Path.GetDirectoryName(_path)!); File.WriteAllText(_path, JsonSerializer.Serialize(_items)); } catch { } } return note.Id; } public List List() { lock (_gate) return _items.ToList(); } public List Search(string query) { var q = query?.Trim() ?? ""; return List().Where(n => q.Length == 0 || n.Title.Contains(q, StringComparison.OrdinalIgnoreCase) || n.Body.Contains(q, StringComparison.OrdinalIgnoreCase)).ToList(); } public void Delete(string id) { lock (_gate) { _items.RemoveAll(n => n.Id == id); try { File.WriteAllText(_path, JsonSerializer.Serialize(_items)); } catch { } } } /// UC-K19 명시적 저장(Ctrl+S) — 현재 목록을 파일에 다시 기록한다. public void Save() { lock (_gate) { try { File.WriteAllText(_path, JsonSerializer.Serialize(_items)); } catch { } } } }