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

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

/// Private implementation type for `_InMemoryApplicationRepositories` 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 _InMemoryApplicationRepositories
    implements ApplicationUnitOfWorkRepositories {
  /// Creates a `_InMemoryApplicationRepositories` 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.
  _InMemoryApplicationRepositories(_InMemoryApplicationState state)
      : tasks = _UnitOfWorkTaskRepository(
          tasksById: state.tasksById,
          ownersById: state.taskOwnersById,
          revisionsById: state.taskRevisionsById,
        ),
        projects = _UnitOfWorkProjectRepository(
          projectsById: state.projectsById,
          ownersById: state.projectOwnersById,
          revisionsById: state.projectRevisionsById,
        ),
        lockedBlocks = _UnitOfWorkLockedBlockRepository(
          blocksById: state.lockedBlocksById,
          blockOwnersById: state.lockedBlockOwnersById,
          blockRevisionsById: state.lockedBlockRevisionsById,
          overridesById: state.lockedOverridesById,
          overrideOwnersById: state.lockedOverrideOwnersById,
          overrideRevisionsById: state.lockedOverrideRevisionsById,
        ),
        schedulingSnapshots = _UnitOfWorkSchedulingSnapshotRepository(
          state.schedulingSnapshotsById,
        ),
        taskActivities = _UnitOfWorkTaskActivityRepository(
          activitiesById: state.taskActivitiesById,
          ownersById: state.taskActivityOwnersById,
        ),
        projectStatistics = _UnitOfWorkProjectStatisticsRepository(
          statisticsByProjectId: state.projectStatisticsByProjectId,
          ownersByProjectId: state.projectStatisticsOwnersByProjectId,
          revisionsByProjectId: state.projectStatisticsRevisionsByProjectId,
        ),
        ownerSettings = _UnitOfWorkOwnerSettingsRepository(
          settingsByOwnerId: state.ownerSettingsByOwnerId,
          revisionsByOwnerId: state.ownerSettingsRevisionsByOwnerId,
        ),
        noticeAcknowledgements = _UnitOfWorkNoticeAcknowledgementRepository(
          recordsByScopedId: state.noticeAcknowledgementsByScopedId,
          revisionsByScopedId: state.noticeAcknowledgementRevisionsByScopedId,
        ),
        operations = _UnitOfWorkOperationRepository(state.operationsById);

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

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

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

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

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

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

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

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

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