glp-companion/lib/features/medication/domain/repositories/medication_repository.dart

25 lines
1.0 KiB
Dart

import '../entities/dose_entry.dart';
/// Persistence contract for the medication bounded context.
///
/// The presentation layer depends only on this interface; the drift-backed
/// implementation lives in `data/repositories/` so widgets and controllers
/// remain testable with in-memory fakes.
abstract class IMedicationRepository {
/// Emits the full dose history (newest first) whenever it changes.
Stream<List<DoseEntry>> watchDoseEntries({int limit = 500});
/// One-shot snapshot of the dose history (newest first).
Future<List<DoseEntry>> getDoseEntries({int limit = 500});
/// Persists [entry]; when [DoseEntry.id] is `null` a new row is inserted,
/// otherwise the existing row is updated. Returns the stored entry with its
/// database-assigned identifier.
Future<DoseEntry> saveDoseEntry(DoseEntry entry);
/// Removes the entry with [id], if present.
Future<void> deleteDoseEntry(int id);
/// Most recent actually-administered dose, or `null` on an empty history.
Future<DoseEntry?> getLatestAdministeredDose();
}