class ServerConfig { final String host; final int port; final String? localHost; final String? macAddress; const ServerConfig({ required this.host, this.port = 8765, this.localHost, this.macAddress, }); /// Primary WebSocket URL (local network). String get localUrl { final h = localHost ?? host; return 'ws://$h:$port'; } /// Fallback WebSocket URL (remote / public). String get remoteUrl => 'ws://$host:$port'; /// Returns [localUrl, remoteUrl] for dual-connect attempts. List get urls { if (localHost != null && localHost!.isNotEmpty && localHost != host) { return [localUrl, remoteUrl]; } return [remoteUrl]; } Map toJson() { return { 'host': host, 'port': port, if (localHost != null) 'localHost': localHost, if (macAddress != null) 'macAddress': macAddress, }; } factory ServerConfig.fromJson(Map json) { return ServerConfig( host: json['host'] as String? ?? '', port: json['port'] as int? ?? 8765, localHost: json['localHost'] as String?, macAddress: json['macAddress'] as String?, ); } ServerConfig copyWith({ String? host, int? port, String? localHost, String? macAddress, }) { return ServerConfig( host: host ?? this.host, port: port ?? this.port, localHost: localHost ?? this.localHost, macAddress: macAddress ?? this.macAddress, ); } }