// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

part of '../../child_tasks.dart';

/// Result from child/parent completion propagation.
class ChildTaskCompletionResult {
  /// Creates a `ChildTaskCompletionResult` instance with the values required by its invariants.
  /// Callers should pass already-normalized scheduler data because validation and defaulting belong at the model or service boundary, not in arbitrary UI code.
  ChildTaskCompletionResult({
    required List<Task> tasks,
    required List<String> changedTaskIds,
    this.completedChildId,
    this.completedParentId,
    List<String> forceCompletedChildIds = const <String>[],
    List<TaskActivity> activities = const <TaskActivity>[],
    List<TaskTransitionOutcomeCode> transitionOutcomeCodes =
        const <TaskTransitionOutcomeCode>[],
    this.autoCompletedParent = false,
    this.canCompleteParentExplicitly = false,
  })  : tasks = List<Task>.unmodifiable(tasks),
        changedTaskIds = List<String>.unmodifiable(changedTaskIds),
        forceCompletedChildIds =
            List<String>.unmodifiable(forceCompletedChildIds),
        activities = List<TaskActivity>.unmodifiable(activities),
        transitionOutcomeCodes = List<TaskTransitionOutcomeCode>.unmodifiable(
            transitionOutcomeCodes);

  /// Replacement task list after the completion action.
  final List<Task> tasks;

  /// Task ids whose completion state changed.
  final List<String> changedTaskIds;

  /// Child id completed by the initial child-complete action, when applicable.
  final String? completedChildId;

  /// Parent id completed by the action, when applicable.
  final String? completedParentId;

  /// Direct child ids completed by explicit parent-complete behavior.
  final List<String> forceCompletedChildIds;

  /// Internal activities produced by parent/child completion propagation.
  final List<TaskActivity> activities;

  /// Transition outcomes returned while applying completion propagation.
  final List<TaskTransitionOutcomeCode> transitionOutcomeCodes;

  /// Whether the parent was completed because all direct children are complete.
  final bool autoCompletedParent;

  /// Whether callers may offer an explicit parent-complete action.
  final bool canCompleteParentExplicitly;
}
