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

part of '../../persistence.dart';

/// Minimal Either type for expected repository success/failure paths.
sealed class Either<L, R> {
  /// Creates a `Either` 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.
  const Either();

  /// Whether this value is a left/failure value.
  bool get isLeft => this is Left<L, R>;

  /// Whether this value is a right/success value.
  bool get isRight => this is Right<L, R>;

  /// Return the left value or throw when this is right.
  L get left => switch (this) {
        Left<L, R>(:final value) => value,
        Right<L, R>() => throw StateError('Either does not contain left.'),
      };

  /// Return the right value or throw when this is left.
  R get right => switch (this) {
        Left<L, R>() => throw StateError('Either does not contain right.'),
        Right<L, R>(:final value) => value,
      };
}
