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

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

/// Document mapping for [NoticeAcknowledgementRecord].
abstract final class NoticeAcknowledgementDocumentMapping {
  /// 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(
    NoticeAcknowledgementRecord record, {
    int revision = 1,
  }) {
    return {
      ..._commonFields(
        id: record.noticeId,
        ownerId: record.ownerId,
        revision: revision,
        createdAt: record.acknowledgedAt,
        updatedAt: record.acknowledgedAt,
      ),
      NoticeAcknowledgementDocumentFields.noticeId: record.noticeId,
      NoticeAcknowledgementDocumentFields.acknowledgedAt:
          PersistenceDateTimeConvention.toStoredString(record.acknowledgedAt),
    };
  }

  /// 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 NoticeAcknowledgementRecord fromDocument(
    Map<String, Object?> document,
  ) {
    return _mapInvalidValues(() {
      _readCommon(document);
      return NoticeAcknowledgementRecord(
        noticeId: _requiredString(
          document,
          NoticeAcknowledgementDocumentFields.noticeId,
        ),
        ownerId: _requiredString(
          document,
          NoticeAcknowledgementDocumentFields.ownerId,
        ),
        acknowledgedAt: _requiredDateTime(
          document,
          NoticeAcknowledgementDocumentFields.acknowledgedAt,
        ),
      );
    });
  }
}
