import 'package:equatable/equatable.dart'; import '../../../../core/network/ws_client.dart'; import '../../domain/entities/game_entities.dart'; /// یک بازیکن در اتاق انتظارِ میز خصوصی. class LobbyPlayer { final String name; final bool host; const LobbyPlayer(this.name, this.host); } /// وضعیت اتاق انتظارِ میز خصوصی (دورهمی). class TableLobby { final String code; final List players; final bool isHost; final int remaining; final bool unlimited; const TableLobby({ required this.code, required this.players, required this.isHost, required this.remaining, required this.unlimited, }); factory TableLobby.fromJson(Map j) => TableLobby( code: (j['code'] ?? '') as String, players: ((j['players'] as List?) ?? []) .map((e) => LobbyPlayer( (e['name'] ?? '') as String, (e['host'] ?? false) as bool)) .toList(), isHost: (j['host'] ?? false) as bool, remaining: (j['remaining'] ?? 0) as int, unlimited: (j['unlimited'] ?? false) as bool, ); String get sig => '$code|$isHost|$remaining|$unlimited|' '${players.map((p) => '${p.name}${p.host ? '*' : ''}').join(',')}'; } class GameUiState extends Equatable { final WsStatus connection; final GameState? state; final HandResult? handResult; final GameOver? gameOver; final String? notice; final TableLobby? lobby; final int? countdown; final bool tableClosed; const GameUiState({ this.connection = WsStatus.connecting, this.state, this.handResult, this.gameOver, this.notice, this.lobby, this.countdown, this.tableClosed = false, }); GameUiState copyWith({ WsStatus? connection, GameState? state, HandResult? handResult, GameOver? gameOver, String? notice, TableLobby? lobby, int? countdown, bool? tableClosed, bool clearHandResult = false, bool clearNotice = false, }) => GameUiState( connection: connection ?? this.connection, state: state ?? this.state, handResult: clearHandResult ? null : (handResult ?? this.handResult), gameOver: gameOver ?? this.gameOver, notice: clearNotice ? null : (notice ?? this.notice), lobby: lobby ?? this.lobby, countdown: countdown ?? this.countdown, tableClosed: tableClosed ?? this.tableClosed, ); @override List get props => [ connection, state, handResult, gameOver, notice, lobby?.sig, countdown, tableClosed, ]; }