import 'package:equatable/equatable.dart';

enum ConnectionOverallStatus { disconnected, connecting, connected, partial }

class ConnectionState extends Equatable {
  final ConnectionOverallStatus overallStatus;
  final Map<String, bool> serverStatus;
  final String? error;

  const ConnectionState({
    this.overallStatus = ConnectionOverallStatus.disconnected,
    this.serverStatus = const {},
    this.error,
  });

  /// Check if all servers are connected
  bool get allConnected =>
      serverStatus.isNotEmpty && serverStatus.values.every((v) => v);

  /// Check if any server is connected
  bool get anyConnected => serverStatus.values.any((v) => v);

  /// Get count of connected servers
  int get connectedCount => serverStatus.values.where((v) => v).length;

  /// Get count of total servers
  int get totalCount => serverStatus.length;

  ConnectionState copyWith({
    ConnectionOverallStatus? overallStatus,
    Map<String, bool>? serverStatus,
    String? error,
  }) {
    return ConnectionState(
      overallStatus: overallStatus ?? this.overallStatus,
      serverStatus: serverStatus ?? this.serverStatus,
      error: error,
    );
  }

  @override
  List<Object?> get props => [overallStatus, serverStatus, error];
}
