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

part of '../../document_mapping.dart';

/// Document mapping for [TaskStatistics].
abstract final class TaskStatisticsDocumentMapping {
  /// Converts scheduler data for `toDocument` without changing the source object.
  /// Conversion helpers keep persistence and export shapes explicit so domain models do not depend on storage-specific details.
  static Map<String, Object?> toDocument(TaskStatistics stats) {
    return {
      TaskStatisticsDocumentFields.skippedDuringBurnoutCount:
          stats.skippedDuringBurnoutCount,
      TaskStatisticsDocumentFields.manuallyPushedCount:
          stats.manuallyPushedCount,
      TaskStatisticsDocumentFields.autoPushedCount: stats.autoPushedCount,
      TaskStatisticsDocumentFields.movedToBacklogCount:
          stats.movedToBacklogCount,
      TaskStatisticsDocumentFields.restoredFromBacklogCount:
          stats.restoredFromBacklogCount,
      TaskStatisticsDocumentFields.missedCount: stats.missedCount,
      TaskStatisticsDocumentFields.cancelledCount: stats.cancelledCount,
      TaskStatisticsDocumentFields.completedLateCount: stats.completedLateCount,
      TaskStatisticsDocumentFields.completedDuringLockedHoursCount:
          stats.completedDuringLockedHoursCount,
      TaskStatisticsDocumentFields.completedDuringLockedHoursMinutes:
          stats.completedDuringLockedHoursMinutes,
      TaskStatisticsDocumentFields.completedAfterShieldCount:
          stats.completedAfterShieldCount,
      TaskStatisticsDocumentFields.completedAfterPushCount:
          stats.completedAfterPushCount,
      TaskStatisticsDocumentFields.totalPushesBeforeCompletion:
          stats.totalPushesBeforeCompletion,
    };
  }

  /// Converts scheduler data for `fromDocument` without changing the source object.
  /// Conversion helpers keep persistence and export shapes explicit so domain models do not depend on storage-specific details.
  static TaskStatistics fromDocument(Map<String, Object?> document) {
    return _mapInvalidValues(() {
      return TaskStatistics(
        skippedDuringBurnoutCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.skippedDuringBurnoutCount,
        ),
        manuallyPushedCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.manuallyPushedCount,
        ),
        autoPushedCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.autoPushedCount,
        ),
        movedToBacklogCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.movedToBacklogCount,
        ),
        restoredFromBacklogCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.restoredFromBacklogCount,
        ),
        missedCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.missedCount,
        ),
        cancelledCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.cancelledCount,
        ),
        completedLateCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.completedLateCount,
        ),
        completedDuringLockedHoursCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.completedDuringLockedHoursCount,
        ),
        completedDuringLockedHoursMinutes: _requiredInt(
          document,
          TaskStatisticsDocumentFields.completedDuringLockedHoursMinutes,
        ),
        completedAfterShieldCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.completedAfterShieldCount,
        ),
        completedAfterPushCount: _requiredInt(
          document,
          TaskStatisticsDocumentFields.completedAfterPushCount,
        ),
        totalPushesBeforeCompletion: _requiredInt(
          document,
          TaskStatisticsDocumentFields.totalPushesBeforeCompletion,
        ),
      );
    });
  }
}
