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

part of '../../persistence_contract.dart';

/// Pure guard helpers for bounded embedded document payloads.
abstract final class PersistencePayloadGuard {
  /// Performs the `mapEntries` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static PersistenceGuardResult mapEntries({
    required String fieldName,
    required Map<Object?, Object?> value,
    required int limit,
  }) {
    if (value.length > limit) {
      return PersistenceGuardResult.tooLarge(
        fieldName: fieldName,
        limit: limit,
        actual: value.length,
      );
    }
    return PersistenceGuardResult.valid();
  }

  /// Performs the `listLength` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static PersistenceGuardResult listLength({
    required String fieldName,
    required Iterable<Object?> value,
    required int limit,
  }) {
    final actual = value.length;
    if (actual > limit) {
      return PersistenceGuardResult.tooLarge(
        fieldName: fieldName,
        limit: limit,
        actual: actual,
      );
    }
    return PersistenceGuardResult.valid();
  }
}
