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

part of '../repository_values.dart';

/// One bounded page of repository query results.
class Page<T> {
  /// Creates a `Page` instance with the values required by its invariants.
  /// Callers should pass already-normalized scheduler data because validation and defaulting belong at the model or service boundary, not in arbitrary UI code.
  Page({
    required Iterable<T> items,
    this.nextCursor,
  }) : items = List<T>.unmodifiable(items);

  /// Items returned for this page.
  final List<T> items;

  /// Cursor for the next page, or null when this is the last page.
  final String? nextCursor;

  /// Whether another page is available.
  bool get hasMore => nextCursor != null;
}

/// Top-level helper that performs the `_requiredTrimmed` operation for this file.
/// Keeping the helper private makes the surrounding flow easier to read while preventing unrelated libraries from depending on implementation detail.
String _requiredTrimmed(String value, String name) {
  final trimmed = value.trim();
  if (trimmed.isEmpty) {
    throw ArgumentError.value(value, name, 'Value must not be blank.');
  }
  return trimmed;
}
