uto_manager/lib/domain/entities/unit_node.dart

74 lines
2.2 KiB
Dart

import 'package:equatable/equatable.dart';
import 'package:uto_manager/domain/entities/doctrinal_branch.dart';
import 'package:uto_manager/domain/entities/echelon.dart';
/// Represents a single organizational unit node in the UTO hierarchy.
///
/// A [UnitNode] can represent any echelon from Brigade down to Team.
/// Nodes form a tree structure via [parentUnitId] references.
class UnitNode extends Equatable {
const UnitNode({
required this.unitId,
required this.echelon,
required this.branch,
required this.name,
required this.isKeyLeader,
this.parentUnitId,
});
/// Unique identifier for this unit (UUID v4).
final String unitId;
/// The echelon level of this unit.
final Echelon echelon;
/// The functional branch/specialty of this unit.
final DoctrinalBranch branch;
/// The parent unit's ID, or null if this is a root node (Brigade HQ).
final String? parentUnitId;
/// The display name of this unit (e.g., "1st Platoon", "Alpha Company").
final String name;
/// Whether this node represents a key leader position.
final bool isKeyLeader;
/// Returns true if this unit has no parent (is a root/top-level unit).
bool get isRoot => parentUnitId == null;
/// Returns a copy of this [UnitNode] with the given fields replaced.
UnitNode copyWith({
String? unitId,
Echelon? echelon,
DoctrinalBranch? branch,
String? parentUnitId,
String? name,
bool? isKeyLeader,
bool clearParent = false,
}) {
return UnitNode(
unitId: unitId ?? this.unitId,
echelon: echelon ?? this.echelon,
branch: branch ?? this.branch,
parentUnitId: clearParent ? null : (parentUnitId ?? this.parentUnitId),
name: name ?? this.name,
isKeyLeader: isKeyLeader ?? this.isKeyLeader,
);
}
/// Returns true if [potentialParent] is a doctrinally valid parent for
/// this unit based on echelon hierarchy rules.
bool isValidParentNode(UnitNode potentialParent) {
return echelon.isValidParent(potentialParent.echelon);
}
@override
List<Object?> get props => [unitId, echelon, branch, parentUnitId, name, isKeyLeader];
@override
String toString() => 'UnitNode(id: $unitId, name: $name, '
'echelon: ${echelon.displayName}, branch: ${branch.displayName})';
}