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

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

/// Document mapping for [SchedulingChange].
abstract final class SchedulingChangeDocumentMapping {
  /// 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(SchedulingChange change) {
    return {
      SchedulingChangeDocumentFields.taskId: change.taskId,
      SchedulingChangeDocumentFields.previousStart:
          _dateTimeToStored(change.previousStart),
      SchedulingChangeDocumentFields.previousEnd:
          _dateTimeToStored(change.previousEnd),
      SchedulingChangeDocumentFields.nextStart:
          _dateTimeToStored(change.nextStart),
      SchedulingChangeDocumentFields.nextEnd: _dateTimeToStored(change.nextEnd),
    };
  }

  /// 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 SchedulingChange fromDocument(Map<String, Object?> document) {
    return _mapInvalidValues(() {
      return SchedulingChange(
        taskId:
            _requiredString(document, SchedulingChangeDocumentFields.taskId),
        previousStart: _requiredNullableDateTime(
          document,
          SchedulingChangeDocumentFields.previousStart,
        ),
        previousEnd: _requiredNullableDateTime(
          document,
          SchedulingChangeDocumentFields.previousEnd,
        ),
        nextStart: _requiredNullableDateTime(
          document,
          SchedulingChangeDocumentFields.nextStart,
        ),
        nextEnd: _requiredNullableDateTime(
          document,
          SchedulingChangeDocumentFields.nextEnd,
        ),
      );
    });
  }
}
