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

part of '../../time_contracts.dart';

/// Simple deterministic ID generator useful for tests and local wiring.
class SequentialIdGenerator implements IdGenerator {
  /// Creates a `SequentialIdGenerator` 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.
  SequentialIdGenerator({
    this.prefix = 'id',
    int start = 1,
  }) : _next = start;

  /// Stores the `prefix` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final String prefix;

  /// Private state stored as `_next` for this implementation.
  /// The field is intentionally scoped to this library so only the owning type can change the related scheduler or UI behavior.
  int _next;

  /// Performs the `nextId` 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.
  @override
  String nextId() {
    final id = '$prefix-$_next';
    _next += 1;
    return id;
  }
}
