import 'package:uuid/uuid.dart'; import '../models/note.dart'; import '../repositories/local_note_repository.dart'; import 'sync_service.dart'; class NoteService { final LocalNoteRepository _local; final SyncService? _sync; final _uuid = const Uuid(); NoteService({ required LocalNoteRepository local, SyncService? sync, }) : _local = local, _sync = sync; Future> getAllNotes() => _local.getAll(); Future createNote({String title = '', String content = ''}) async { final note = Note( id: _uuid.v4(), title: title, content: content, createdAt: DateTime.now(), updatedAt: DateTime.now(), ); await _local.save(note); return note; } Future updateNote(Note note) async { final updated = note.copyWith(updatedAt: DateTime.now()); await _local.save(updated); return updated; } Future deleteNote(String id) async { await _local.delete(id); } /// Manual backup — push everything to the server. Future triggerBackup() async { if (_sync == null) throw Exception('Backup not configured'); await _sync!.pushAll(); } /// Restore — pull everything from the server. Future triggerRestore() async { if (_sync == null) throw Exception('Backup not configured'); await _sync!.pullAll(); } }