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

part of '../../task_lifecycle.dart';

/// Result of applying one canonical transition.
class TaskTransitionResult {
  /// Creates a `TaskTransitionResult` 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.
  TaskTransitionResult({
    required this.transitionCode,
    required this.outcomeCode,
    required this.task,
    List<TaskActivity> activities = const <TaskActivity>[],
    this.duplicateOfActivityId,
  }) : activities = List<TaskActivity>.unmodifiable(activities);

  /// Requested transition.
  final TaskTransitionCode transitionCode;

  /// Typed outcome for callers.
  final TaskTransitionOutcomeCode outcomeCode;

  /// Original or updated task.
  final Task task;

  /// New internal activity records. Empty for no-op, invalid, and duplicates.
  final List<TaskActivity> activities;

  /// Existing activity id matched by a duplicate operation, when available.
  final String? duplicateOfActivityId;

  /// Convenience flag for mutation persistence.
  bool get applied => outcomeCode == TaskTransitionOutcomeCode.applied;
}
