import 'package:uto_manager/domain/entities/echelon.dart'; import 'package:uto_manager/domain/entities/unit_node.dart'; /// Abstract repository interface for [UnitNode] persistence operations. /// /// Implementations are provided by the infrastructure layer (Drift/SQLite /// for Windows/Android, IndexedDB for Web). The domain layer depends only /// on this interface, never on concrete implementations. abstract interface class UnitRepository { /// Returns all unit nodes in the database. Future> getAll(); /// Returns the unit node with the given [unitId], or null if not found. Future getById(String unitId); /// Returns all direct children of the unit with [parentUnitId]. Future> getChildren(String parentUnitId); /// Returns all root units (units with no parent). Future> getRoots(); /// Returns all units at the given [echelon] level. Future> getByEchelon(Echelon echelon); /// Returns the full subtree rooted at [unitId] (inclusive). Future> getSubtree(String unitId); /// Inserts a new [unit] into the repository. /// /// Throws [StateError] if a unit with the same ID already exists. Future insert(UnitNode unit); /// Inserts multiple [units] in a single atomic transaction. Future insertAll(List units); /// Updates an existing [unit] in the repository. /// /// Throws [StateError] if no unit with the given ID exists. Future update(UnitNode unit); /// Deletes the unit with [unitId] from the repository. /// /// Does not cascade-delete children; caller is responsible for /// re-parenting or deleting child units first. Future delete(String unitId); /// Deletes the unit with [unitId] and all its descendants. Future deleteSubtree(String unitId); /// Re-parents the unit with [unitId] to the unit with [newParentId]. /// /// Validates that the new parent echelon is compatible before executing. /// Throws [ArgumentError] if the re-parenting would violate doctrine. Future reparent(String unitId, String newParentId); /// Returns a stream that emits the full unit list whenever it changes. Stream> watchAll(); /// Returns a stream that emits the subtree rooted at [unitId] on changes. Stream> watchSubtree(String unitId); /// Deletes all units from the repository (used for template reset). Future deleteAll(); }