import 'package:equatable/equatable.dart';
import 'package:krow_domain/krow_domain.dart';

/// Enum representing the status of the client hubs state.
enum ClientHubsStatus {
  initial,
  loading,
  success,
  failure,
  actionInProgress,
  actionSuccess,
  actionFailure,
}

/// State class for the ClientHubs BLoC.
class ClientHubsState extends Equatable {
  final ClientHubsStatus status;
  final List<Hub> hubs;
  final String? errorMessage;
  final String? successMessage;

  /// Whether the "Add Hub" dialog should be visible.
  final bool showAddHubDialog;

  /// The hub currently being identified/assigned an NFC tag.
  /// If null, the identification dialog is closed.
  final Hub? hubToIdentify;

  const ClientHubsState({
    this.status = ClientHubsStatus.initial,
    this.hubs = const <Hub>[],
    this.errorMessage,
    this.successMessage,
    this.showAddHubDialog = false,
    this.hubToIdentify,
  });

  ClientHubsState copyWith({
    ClientHubsStatus? status,
    List<Hub>? hubs,
    String? errorMessage,
    String? successMessage,
    bool? showAddHubDialog,
    Hub? hubToIdentify,
    bool clearHubToIdentify = false,
    bool clearErrorMessage = false,
    bool clearSuccessMessage = false,
  }) {
    return ClientHubsState(
      status: status ?? this.status,
      hubs: hubs ?? this.hubs,
      errorMessage: clearErrorMessage
          ? null
          : (errorMessage ?? this.errorMessage),
      successMessage: clearSuccessMessage
          ? null
          : (successMessage ?? this.successMessage),
      showAddHubDialog: showAddHubDialog ?? this.showAddHubDialog,
      hubToIdentify: clearHubToIdentify
          ? null
          : (hubToIdentify ?? this.hubToIdentify),
    );
  }

  @override
  List<Object?> get props => <Object?>[
    status,
    hubs,
    errorMessage,
    successMessage,
    showAddHubDialog,
    hubToIdentify,
  ];
}
