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

part of '../../../../application_layer.dart';

/// Atomic application transaction boundary.
abstract interface class ApplicationUnitOfWork {
  /// Runs the `run<T>` operation and completes after its asynchronous work finishes.
  /// Callers should await the returned future so repository writes, UI refreshes, and failure handling happen in a predictable order.
  Future<ApplicationResult<T>> run<T>({
    required ApplicationOperationContext context,
    required String operationName,
    required Future<ApplicationResult<T>> Function(
      ApplicationUnitOfWorkRepositories repositories,
    ) action,
  });

  /// Runs the `read<T>` operation and completes after its asynchronous work finishes.
  /// Callers should await the returned future so repository writes, UI refreshes, and failure handling happen in a predictable order.
  Future<ApplicationResult<T>> read<T>({
    required Future<ApplicationResult<T>> Function(
      ApplicationUnitOfWorkRepositories repositories,
    ) action,
  });
}
