uto_manager/lib/domain/repositories/personnel_repository.dart

61 lines
2.4 KiB
Dart

import 'package:uto_manager/domain/entities/authorized_rank.dart';
import 'package:uto_manager/domain/entities/personnel_record.dart';
import 'package:uto_manager/domain/value_objects/duty_mos.dart';
/// Abstract repository interface for [PersonnelRecord] persistence operations.
///
/// Implementations are provided by the infrastructure layer. The domain layer
/// depends only on this interface, never on concrete implementations.
abstract interface class PersonnelRepository {
/// Returns all personnel records in the database.
Future<List<PersonnelRecord>> getAll();
/// Returns the personnel record with [soldierId], or null if not found.
Future<PersonnelRecord?> getById(String soldierId);
/// Returns all soldiers assigned to the slot with [slotId].
Future<List<PersonnelRecord>> getBySlot(String slotId);
/// Returns all unassigned soldiers (not assigned to any slot).
Future<List<PersonnelRecord>> getUnassigned();
/// Returns all soldiers with the given [primaryMos].
Future<List<PersonnelRecord>> getByMos(DutyMos primaryMos);
/// Returns all soldiers at the given [payGrade].
Future<List<PersonnelRecord>> getByPayGrade(AuthorizedRank payGrade);
/// Inserts a new [record] into the repository.
///
/// Throws [StateError] if a record with the same soldier ID already exists.
Future<void> insert(PersonnelRecord record);
/// Inserts multiple [records] in a single atomic transaction.
Future<void> insertAll(List<PersonnelRecord> records);
/// Updates an existing [record] in the repository.
///
/// Throws [StateError] if no record with the given soldier ID exists.
Future<void> update(PersonnelRecord record);
/// Deletes the personnel record with [soldierId].
Future<void> delete(String soldierId);
/// Assigns the soldier with [soldierId] to the slot with [slotId].
///
/// Clears any previous slot assignment for this soldier.
Future<void> assignToSlot(String soldierId, String slotId);
/// Removes the slot assignment for the soldier with [soldierId].
Future<void> unassignFromSlot(String soldierId);
/// Returns a stream that emits the full personnel list whenever it changes.
Stream<List<PersonnelRecord>> watchAll();
/// Returns a stream that emits unassigned soldiers whenever the list changes.
Stream<List<PersonnelRecord>> watchUnassigned();
/// Deletes all personnel records from the repository.
Future<void> deleteAll();
}