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

part of '../../document_migration.dart';

/// Migration output plus report.
class DocumentMigrationResult {
  /// Creates a `DocumentMigrationResult` 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.
  const DocumentMigrationResult({
    required this.report,
    required this.document,
  });

  /// Migrated/current document. Null means the source must not be overwritten.
  final Map<String, Object?>? document;

  /// Stores the `report` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final DocumentMigrationReport report;

  /// Returns the derived `isSuccess` value for this object.
  /// Keeping this as an accessor gives callers a stable read surface while the owning type controls how the value is calculated.
  bool get isSuccess => report.status != DocumentMigrationStatus.failed;

  /// True only when the caller should persist a transformed replacement.
  bool get shouldWrite => report.status == DocumentMigrationStatus.migrated;
}
