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

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

/// Repository loader for common scheduler input assembly.
class ApplicationSchedulingLoader {
  /// Creates a `ApplicationSchedulingLoader` 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 ApplicationSchedulingLoader(this.repositories);

  /// Repositories for the current application operation.
  final ApplicationUnitOfWorkRepositories repositories;

  /// Load scheduler input for [window] from the repository boundary.
  ///
  /// UI code should not persist partial [SchedulingResult] objects. Commands
  /// should load authoritative state here, invoke domain services, then commit
  /// resulting entities through a unit of work.
  Future<SchedulingInput> loadInputForWindow({
    required SchedulingWindow window,
    List<TimeInterval> lockedIntervals = const <TimeInterval>[],
    List<TimeInterval> requiredVisibleIntervals = const <TimeInterval>[],
  }) async {
    final scheduledTasks = await repositories.tasks.findScheduledInWindow(
      window,
    );
    return SchedulingInput(
      tasks: scheduledTasks,
      window: window,
      lockedIntervals: lockedIntervals,
      requiredVisibleIntervals: requiredVisibleIntervals,
    );
  }
}
