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

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

/// Document mapping for [SchedulingWindow].
abstract final class SchedulingWindowDocumentMapping {
  /// 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(SchedulingWindow window) {
    return {
      SchedulingWindowDocumentFields.start:
          PersistenceDateTimeConvention.toStoredString(window.start),
      SchedulingWindowDocumentFields.end:
          PersistenceDateTimeConvention.toStoredString(window.end),
    };
  }

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