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

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

/// Private implementation type for `_InMemoryApplicationState` in this library.
/// It keeps supporting state and behavior scoped to the owning file so the public API stays focused on the scheduler concepts that callers use directly.
class _InMemoryApplicationState {
  /// Creates a `_InMemoryApplicationState` 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.
  _InMemoryApplicationState({
    required this.tasksById,
    required this.taskOwnersById,
    required this.taskRevisionsById,
    required this.projectsById,
    required this.projectOwnersById,
    required this.projectRevisionsById,
    required this.lockedBlocksById,
    required this.lockedBlockOwnersById,
    required this.lockedBlockRevisionsById,
    required this.lockedOverridesById,
    required this.lockedOverrideOwnersById,
    required this.lockedOverrideRevisionsById,
    required this.schedulingSnapshotsById,
    required this.taskActivitiesById,
    required this.taskActivityOwnersById,
    required this.projectStatisticsByProjectId,
    required this.projectStatisticsOwnersByProjectId,
    required this.projectStatisticsRevisionsByProjectId,
    required this.ownerSettingsByOwnerId,
    required this.ownerSettingsRevisionsByOwnerId,
    required this.noticeAcknowledgementsByScopedId,
    required this.noticeAcknowledgementRevisionsByScopedId,
    required this.operationsById,
  });

  /// Stores the `tasksById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, Task> tasksById;

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

  /// Stores the `taskRevisionsById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, int> taskRevisionsById;

  /// Stores the `projectsById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, ProjectProfile> projectsById;

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

  /// Stores the `projectRevisionsById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, int> projectRevisionsById;

  /// Stores the `lockedBlocksById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, LockedBlock> lockedBlocksById;

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

  /// Stores the `lockedBlockRevisionsById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, int> lockedBlockRevisionsById;

  /// Stores the `lockedOverridesById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, LockedBlockOverride> lockedOverridesById;

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

  /// Stores the `lockedOverrideRevisionsById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, int> lockedOverrideRevisionsById;

  /// Stores the `schedulingSnapshotsById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, SchedulingStateSnapshot> schedulingSnapshotsById;

  /// Stores the `taskActivitiesById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, TaskActivity> taskActivitiesById;

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

  /// Stores the `projectStatisticsByProjectId` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, ProjectStatistics> projectStatisticsByProjectId;

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

  /// Stores the `projectStatisticsRevisionsByProjectId` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, int> projectStatisticsRevisionsByProjectId;

  /// Stores the `ownerSettingsByOwnerId` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, OwnerSettings> ownerSettingsByOwnerId;

  /// Stores the `ownerSettingsRevisionsByOwnerId` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, int> ownerSettingsRevisionsByOwnerId;

  /// Stores the `noticeAcknowledgementsByScopedId` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, NoticeAcknowledgementRecord>
      noticeAcknowledgementsByScopedId;

  /// Stores the `noticeAcknowledgementRevisionsByScopedId` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, int> noticeAcknowledgementRevisionsByScopedId;

  /// Stores the `operationsById` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Map<String, ApplicationOperationRecord> operationsById;

  /// Performs the `copy` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  _InMemoryApplicationState copy() {
    return _InMemoryApplicationState(
      tasksById: Map<String, Task>.of(tasksById),
      taskOwnersById: Map<String, String>.of(taskOwnersById),
      taskRevisionsById: Map<String, int>.of(taskRevisionsById),
      projectsById: Map<String, ProjectProfile>.of(projectsById),
      projectOwnersById: Map<String, String>.of(projectOwnersById),
      projectRevisionsById: Map<String, int>.of(projectRevisionsById),
      lockedBlocksById: Map<String, LockedBlock>.of(lockedBlocksById),
      lockedBlockOwnersById: Map<String, String>.of(lockedBlockOwnersById),
      lockedBlockRevisionsById: Map<String, int>.of(
        lockedBlockRevisionsById,
      ),
      lockedOverridesById:
          Map<String, LockedBlockOverride>.of(lockedOverridesById),
      lockedOverrideOwnersById: Map<String, String>.of(
        lockedOverrideOwnersById,
      ),
      lockedOverrideRevisionsById: Map<String, int>.of(
        lockedOverrideRevisionsById,
      ),
      schedulingSnapshotsById:
          Map<String, SchedulingStateSnapshot>.of(schedulingSnapshotsById),
      taskActivitiesById: Map<String, TaskActivity>.of(taskActivitiesById),
      taskActivityOwnersById: Map<String, String>.of(taskActivityOwnersById),
      projectStatisticsByProjectId:
          Map<String, ProjectStatistics>.of(projectStatisticsByProjectId),
      projectStatisticsOwnersByProjectId: Map<String, String>.of(
        projectStatisticsOwnersByProjectId,
      ),
      projectStatisticsRevisionsByProjectId: Map<String, int>.of(
        projectStatisticsRevisionsByProjectId,
      ),
      ownerSettingsByOwnerId: Map<String, OwnerSettings>.of(
        ownerSettingsByOwnerId,
      ),
      ownerSettingsRevisionsByOwnerId: Map<String, int>.of(
        ownerSettingsRevisionsByOwnerId,
      ),
      noticeAcknowledgementsByScopedId:
          Map<String, NoticeAcknowledgementRecord>.of(
        noticeAcknowledgementsByScopedId,
      ),
      noticeAcknowledgementRevisionsByScopedId: Map<String, int>.of(
        noticeAcknowledgementRevisionsByScopedId,
      ),
      operationsById: Map<String, ApplicationOperationRecord>.of(
        operationsById,
      ),
    );
  }
}
