import '../../../../model/tour.dart';

abstract class TourState {}

class TourInitial extends TourState {}

class TourLoading extends TourState {}

class TourLoadingFailed extends TourState {}

class TourLoaded extends TourState {
  Tour tour;
  Map<String, double>? distances;
  List<Payment> paymentOptions;
  Map<String, List<String>> sortingInformation;

  /// Number of scan-related server requests currently in flight. Drives the
  /// inline indicator on the scanner widget. Using a counter (not bool) lets
  /// rapid-fire scans coexist without one prematurely clearing the indicator.
  int pendingScanRequests;

  /// True während der Backend-Call zur Persistierung der Sortier-Reihenfolge
  /// läuft. Wird vom Bestätigungs-Button in der Sortier-Page für Spinner
  /// und Button-Disabled-State ausgewertet.
  bool isPersistingSorting;

  /// Letzte Fehlermeldung des Sortier-Persist-Calls. Wird nach Anzeige
  /// durch das UI ge-leert (z. B. nach SnackBar).
  String? sortingPersistError;

  TourLoaded({
    required this.tour,
    this.distances,
    required this.paymentOptions,
    required this.sortingInformation,
    this.pendingScanRequests = 0,
    this.isPersistingSorting = false,
    this.sortingPersistError,
  });

  TourLoaded copyWith({
    Tour? tour,
    Map<String, double>? distances,
    List<Payment>? paymentOptions,
    Map<String, List<String>>? sortingInformation,
    int? pendingScanRequests,
    bool? isPersistingSorting,
    String? sortingPersistError,
    bool clearSortingPersistError = false,
  }) {
    return TourLoaded(
      tour: tour ?? this.tour,
      distances: distances ?? this.distances,
      paymentOptions: paymentOptions ?? this.paymentOptions,
      sortingInformation: sortingInformation ?? this.sortingInformation,
      pendingScanRequests: pendingScanRequests ?? this.pendingScanRequests,
      isPersistingSorting: isPersistingSorting ?? this.isPersistingSorting,
      sortingPersistError: clearSortingPersistError
          ? null
          : (sortingPersistError ?? this.sortingPersistError),
    );
  }
}
