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

class TcpClientState extends Equatable {
  final TcpConnectionStatus connectionStatus;
  final String? address;
  final int? port;
  final String? error;

  const TcpClientState({
    this.connectionStatus = TcpConnectionStatus.disconnected,
    this.address,
    this.port,
    this.error,
  });

  TcpClientState copyWith({
    TcpConnectionStatus? connectionStatus,
    String? address,
    int? port,
    String? error,
    bool clearError = false,
  }) {
    return TcpClientState(
      connectionStatus: connectionStatus ?? this.connectionStatus,
      address: address ?? this.address,
      port: port ?? this.port,
      error: clearError ? null : (error ?? this.error),
    );
  }

  bool get isConnected => connectionStatus == TcpConnectionStatus.connected;

  @override
  List<Object?> get props => [connectionStatus, address, port, error];
}