call method

  1. @override
Future<ElectricalNode> call({
  1. AddChildNodeParams? params,
})
override

Executes the use case with optional parameters.

Returns a Future that completes with the result of type T. Implementations should handle errors appropriately.

Implementation

@override
Future<ElectricalNode> call({AddChildNodeParams? params}) async {
  if (params == null) throw Exception("Params required");

  final newRoot = _addChildToTree(params.root, params.parentId, params.child);
  if (newRoot == null) {
    throw Exception("Parent node ${params.parentId} not found");
  }
  return newRoot;
}