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

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

/// Document mapping for [SchedulingOverlap].
abstract final class SchedulingOverlapDocumentMapping {
  /// 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(SchedulingOverlap overlap) {
    return {
      SchedulingOverlapDocumentFields.taskId: overlap.taskId,
      SchedulingOverlapDocumentFields.taskInterval:
          TimeIntervalDocumentMapping.toDocument(overlap.taskInterval),
      SchedulingOverlapDocumentFields.blockedInterval:
          TimeIntervalDocumentMapping.toDocument(overlap.blockedInterval),
    };
  }

  /// 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 SchedulingOverlap fromDocument(Map<String, Object?> document) {
    return _mapInvalidValues(() {
      return SchedulingOverlap(
        taskId:
            _requiredString(document, SchedulingOverlapDocumentFields.taskId),
        taskInterval: TimeIntervalDocumentMapping.fromDocument(
          _requiredMap(document, SchedulingOverlapDocumentFields.taskInterval),
        ),
        blockedInterval: TimeIntervalDocumentMapping.fromDocument(
          _requiredMap(
            document,
            SchedulingOverlapDocumentFields.blockedInterval,
          ),
        ),
      );
    });
  }
}
