class RoomGameProviderModel { const RoomGameProviderModel({required this.key, required this.displayName}); final String key; final String displayName; factory RoomGameProviderModel.fromJson(Map json) { return RoomGameProviderModel( key: _asString(json['key']), displayName: _asString(json['displayName']), ); } } class RoomGameProviderListResponseModel { const RoomGameProviderListResponseModel({required this.items}); final List items; factory RoomGameProviderListResponseModel.fromJson( Map json, ) { final list = json['items'] as List? ?? const []; return RoomGameProviderListResponseModel( items: list .whereType>() .map(RoomGameProviderModel.fromJson) .toList(), ); } } class RoomGameShortcutModel { const RoomGameShortcutModel({ required this.gameId, required this.provider, required this.gameType, required this.providerGameId, required this.name, required this.cover, required this.launchMode, required this.gameMode, required this.sort, required this.launchParams, }); final String gameId; final String provider; final String gameType; final String providerGameId; final String name; final String cover; final String launchMode; final int gameMode; final int sort; final Map launchParams; String get vendorType => provider; String get vendorGameId => providerGameId; factory RoomGameShortcutModel.fromJson(Map json) { return RoomGameShortcutModel( gameId: _asString(json['gameId']), provider: _asString(json['provider'] ?? json['vendorType']), gameType: _asString(json['gameType']).isNotEmpty ? _asString(json['gameType']) : _asString(json['provider'] ?? json['vendorType']), providerGameId: _asString(json['providerGameId'] ?? json['vendorGameId']), name: _asString(json['name']), cover: _asString(json['cover']), launchMode: _asString(json['launchMode']), gameMode: _asInt(json['gameMode']), sort: _asInt(json['sort']), launchParams: _asMap(json['launchParams']), ); } } class RoomGameListItemModel { const RoomGameListItemModel({ required this.gameId, required this.provider, required this.gameType, required this.providerGameId, required this.name, required this.cover, required this.category, required this.sort, required this.launchMode, required this.fullScreen, required this.gameMode, required this.safeHeight, required this.orientation, required this.packageVersion, required this.status, required this.launchParams, }); final String gameId; final String provider; final String gameType; final String providerGameId; final String name; final String cover; final String category; final int sort; final String launchMode; final bool fullScreen; final int gameMode; final int safeHeight; final int orientation; final String packageVersion; final String status; final Map launchParams; String get vendorType => provider; String get vendorGameId => providerGameId; bool get isBaishun => provider.toUpperCase() == 'BAISHUN' || gameType.toUpperCase() == 'BAISHUN'; bool get isLeader => provider.toUpperCase() == 'LEADER' || gameType.toUpperCase() == 'LEADER'; factory RoomGameListItemModel.fromJson(Map json) { return RoomGameListItemModel( gameId: _asString(json['gameId']), provider: _asString(json['provider'] ?? json['vendorType']), gameType: _asString(json['gameType']).isNotEmpty ? _asString(json['gameType']) : _asString(json['provider'] ?? json['vendorType']), providerGameId: _asString(json['providerGameId'] ?? json['vendorGameId']), name: _asString(json['name']), cover: _asString(json['cover']), category: _asString(json['category']), sort: _asInt(json['sort']), launchMode: _asString(json['launchMode']), fullScreen: _asBool(json['fullScreen']), gameMode: _asInt(json['gameMode']), safeHeight: _asInt(json['safeHeight']), orientation: _asInt(json['orientation']), packageVersion: _asString(json['packageVersion']), status: _asString(json['status']), launchParams: _asMap(json['launchParams']), ); } factory RoomGameListItemModel.debugMock() { return const RoomGameListItemModel( gameId: 'bs_mock', provider: 'BAISHUN', gameType: 'BAISHUN', providerGameId: '999001', name: 'BAISHUN Mock', cover: '', category: 'CHAT_ROOM', sort: 999999, launchMode: 'H5_REMOTE', fullScreen: true, gameMode: 3, safeHeight: 800, orientation: 1, packageVersion: 'debug', status: 'DEBUG', launchParams: {'gameType': 'BAISHUN'}, ); } } class RoomGameListResponseModel { const RoomGameListResponseModel({required this.items}); final List items; factory RoomGameListResponseModel.fromJson(Map json) { final list = json['items'] as List? ?? const []; return RoomGameListResponseModel( items: list .whereType>() .map(RoomGameListItemModel.fromJson) .toList(), ); } } class BaishunGameConfigModel { const BaishunGameConfigModel({ required this.sceneMode, required this.currencyIcon, this.rawJson = const {}, }); final int sceneMode; final String currencyIcon; final Map rawJson; factory BaishunGameConfigModel.fromJson(Map json) { return BaishunGameConfigModel( sceneMode: _asInt(json['sceneMode']), currencyIcon: _asString(json['currencyIcon']), rawJson: _asMap(json), ); } Map toJson() { return { ...rawJson, 'sceneMode': sceneMode, 'currencyIcon': currencyIcon, }; } } class BaishunBridgeConfigModel { const BaishunBridgeConfigModel({ required this.appName, required this.appChannel, required this.appId, required this.userId, required this.code, required this.roomId, required this.gameMode, required this.language, required this.gsp, required this.gameConfig, this.rawJson = const {}, }); final String appName; final String appChannel; final int appId; final String userId; final String code; final String roomId; final String gameMode; final String language; final int gsp; final BaishunGameConfigModel gameConfig; final Map rawJson; factory BaishunBridgeConfigModel.fromJson(Map json) { return BaishunBridgeConfigModel( appName: _asString(json['appName']), appChannel: _asString(json['appChannel']), appId: _asInt(json['appId']), userId: _asString(json['userId']), code: _asString(json['code']), roomId: _asString(json['roomId']), gameMode: _asString(json['gameMode']), language: _asString(json['language']), gsp: _asInt(json['gsp']), gameConfig: BaishunGameConfigModel.fromJson( json['gameConfig'] as Map? ?? const {}, ), rawJson: _asMap(json), ); } Map toJson() { return { ...rawJson, 'appName': appName, 'appChannel': appChannel, 'appId': appId, 'userId': userId, 'code': code, 'roomId': roomId, 'gameMode': gameMode, 'language': language, 'gsp': gsp, 'gameConfig': gameConfig.toJson(), }; } } class BaishunLaunchEntryModel { const BaishunLaunchEntryModel({ required this.launchMode, required this.entryUrl, required this.previewUrl, required this.downloadUrl, required this.packageVersion, required this.orientation, required this.safeHeight, this.rawJson = const {}, }); final String launchMode; final String entryUrl; final String previewUrl; final String downloadUrl; final String packageVersion; final int orientation; final int safeHeight; final Map rawJson; factory BaishunLaunchEntryModel.fromJson(Map json) { return BaishunLaunchEntryModel( launchMode: _asString(json['launchMode']), entryUrl: _asString(json['entryUrl']), previewUrl: _asString(json['previewUrl']), downloadUrl: _asString(json['downloadUrl']), packageVersion: _asString(json['packageVersion']), orientation: _asInt(json['orientation']), safeHeight: _asInt(json['safeHeight']), rawJson: _asMap(json), ); } Map toJson() { return { ...rawJson, 'launchMode': launchMode, 'entryUrl': entryUrl, 'previewUrl': previewUrl, 'downloadUrl': downloadUrl, 'packageVersion': packageVersion, 'orientation': orientation, 'safeHeight': safeHeight, }; } } class BaishunRoomStateModel { const BaishunRoomStateModel({ required this.roomId, required this.state, required this.provider, required this.gameSessionId, required this.currentGameId, required this.currentProviderGameId, required this.currentGameName, required this.currentGameCover, required this.hostUserId, this.rawJson = const {}, }); final String roomId; final String state; final String provider; final String gameSessionId; final String currentGameId; final String currentProviderGameId; final String currentGameName; final String currentGameCover; final int hostUserId; final Map rawJson; String get currentVendorGameId => currentProviderGameId; factory BaishunRoomStateModel.fromJson(Map json) { return BaishunRoomStateModel( roomId: _asString(json['roomId']), state: _asString(json['state']), provider: _asString(json['provider'] ?? json['vendorType']), gameSessionId: _asString(json['gameSessionId']), currentGameId: _asString(json['currentGameId'] ?? json['currentGameID']), currentProviderGameId: _asString( json['currentProviderGameId'] ?? json['currentVendorGameId'], ), currentGameName: _asString(json['currentGameName']), currentGameCover: _asString(json['currentGameCover']), hostUserId: _asInt(json['hostUserId']), rawJson: _asMap(json), ); } Map toJson() { return { ...rawJson, 'roomId': roomId, 'state': state, 'provider': provider, 'gameSessionId': gameSessionId, 'currentGameId': currentGameId, 'currentProviderGameId': currentProviderGameId, 'currentGameName': currentGameName, 'currentGameCover': currentGameCover, 'hostUserId': hostUserId, }; } } class BaishunLaunchModel { const BaishunLaunchModel({ required this.gameSessionId, required this.provider, required this.gameId, required this.providerGameId, required this.entry, required this.launchConfig, required this.roomState, }); final String gameSessionId; final String provider; final String gameId; final String providerGameId; final BaishunLaunchEntryModel entry; final BaishunBridgeConfigModel launchConfig; final BaishunRoomStateModel roomState; String get vendorType => provider; String get vendorGameId => providerGameId; BaishunBridgeConfigModel get bridgeConfig => launchConfig; factory BaishunLaunchModel.fromJson(Map json) { return BaishunLaunchModel( gameSessionId: _asString(json['gameSessionId']), provider: _asString(json['provider'] ?? json['vendorType']), gameId: _asString(json['gameId']), providerGameId: _asString(json['providerGameId'] ?? json['vendorGameId']), entry: BaishunLaunchEntryModel.fromJson( json['entry'] as Map? ?? const {}, ), launchConfig: BaishunBridgeConfigModel.fromJson( (json['launchConfig'] ?? json['bridgeConfig']) as Map? ?? const {}, ), roomState: BaishunRoomStateModel.fromJson( json['roomState'] as Map? ?? const {}, ), ); } Map toJson() { return { 'gameSessionId': gameSessionId, 'provider': provider, 'gameId': gameId, 'providerGameId': providerGameId, 'entry': entry.toJson(), 'launchConfig': launchConfig.toJson(), 'roomState': roomState.toJson(), }; } } String _asString(dynamic value) { if (value == null) { return ''; } return value.toString().trim(); } int _asInt(dynamic value) { if (value == null) { return 0; } if (value is int) { return value; } if (value is num) { return value.toInt(); } return int.tryParse(value.toString()) ?? 0; } bool _asBool(dynamic value) { if (value is bool) { return value; } if (value is num) { return value != 0; } if (value is String) { return value.toLowerCase() == 'true' || value == '1'; } return false; } Map _asMap(dynamic value) { if (value is Map) { return value; } if (value is Map) { return value.map( (dynamic key, dynamic item) => MapEntry(key.toString(), item), ); } return const {}; }