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

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

/// Document mapping for [TimeInterval].
abstract final class TimeIntervalDocumentMapping {
  /// 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(TimeInterval interval) {
    return {
      TimeIntervalDocumentFields.start:
          PersistenceDateTimeConvention.toStoredString(interval.start),
      TimeIntervalDocumentFields.end:
          PersistenceDateTimeConvention.toStoredString(interval.end),
      TimeIntervalDocumentFields.label: interval.label,
    };
  }

  /// 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 TimeInterval fromDocument(Map<String, Object?> document) {
    return _mapInvalidValues(() {
      return TimeInterval(
        start: _requiredDateTime(document, TimeIntervalDocumentFields.start),
        end: _requiredDateTime(document, TimeIntervalDocumentFields.end),
        label: _requiredNullableString(
          document,
          TimeIntervalDocumentFields.label,
        ),
      );
    });
  }
}
