class RoomGameShortcutModel { const RoomGameShortcutModel({ required this.gameId, required this.vendorType, required this.vendorGameId, required this.name, required this.cover, required this.launchMode, required this.gameMode, }); final String gameId; final String vendorType; final int vendorGameId; final String name; final String cover; final String launchMode; final int gameMode; factory RoomGameShortcutModel.fromJson(Map json) { return RoomGameShortcutModel( gameId: _asString(json['gameId']), vendorType: _asString(json['vendorType']), vendorGameId: _asInt(json['vendorGameId']), name: _asString(json['name']), cover: _asString(json['cover']), launchMode: _asString(json['launchMode']), gameMode: _asInt(json['gameMode']), ); } } class RoomGameListItemModel { const RoomGameListItemModel({ required this.gameId, required this.vendorType, required this.vendorGameId, 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, }); final String gameId; final String vendorType; final int vendorGameId; 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; bool get isBaishun => vendorType.toUpperCase() == 'BAISHUN'; factory RoomGameListItemModel.fromJson(Map json) { return RoomGameListItemModel( gameId: _asString(json['gameId']), vendorType: _asString(json['vendorType']), vendorGameId: _asInt(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']), ); } factory RoomGameListItemModel.debugMock() { return const RoomGameListItemModel( gameId: 'bs_mock', vendorType: 'BAISHUN', vendorGameId: 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', ); } } 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, }); final int sceneMode; final String currencyIcon; factory BaishunGameConfigModel.fromJson(Map json) { return BaishunGameConfigModel( sceneMode: _asInt(json['sceneMode']), currencyIcon: _asString(json['currencyIcon']), ); } Map toJson() { return {'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, }); 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; 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 {}, ), ); } Map toJson() { return { '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, }); final String launchMode; final String entryUrl; final String previewUrl; final String downloadUrl; final String packageVersion; final int orientation; final int safeHeight; 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']), ); } } class BaishunRoomStateModel { const BaishunRoomStateModel({ required this.roomId, required this.state, required this.gameSessionId, required this.currentGameId, required this.currentVendorGameId, required this.currentGameName, required this.currentGameCover, required this.hostUserId, }); final String roomId; final String state; final String gameSessionId; final String currentGameId; final int currentVendorGameId; final String currentGameName; final String currentGameCover; final int hostUserId; factory BaishunRoomStateModel.fromJson(Map json) { return BaishunRoomStateModel( roomId: _asString(json['roomId']), state: _asString(json['state']), gameSessionId: _asString(json['gameSessionId']), currentGameId: _asString(json['currentGameId']), currentVendorGameId: _asInt(json['currentVendorGameId']), currentGameName: _asString(json['currentGameName']), currentGameCover: _asString(json['currentGameCover']), hostUserId: _asInt(json['hostUserId']), ); } } class BaishunLaunchModel { const BaishunLaunchModel({ required this.gameSessionId, required this.vendorType, required this.gameId, required this.vendorGameId, required this.entry, required this.bridgeConfig, required this.roomState, }); final String gameSessionId; final String vendorType; final String gameId; final int vendorGameId; final BaishunLaunchEntryModel entry; final BaishunBridgeConfigModel bridgeConfig; final BaishunRoomStateModel roomState; factory BaishunLaunchModel.fromJson(Map json) { return BaishunLaunchModel( gameSessionId: _asString(json['gameSessionId']), vendorType: _asString(json['vendorType']), gameId: _asString(json['gameId']), vendorGameId: _asInt(json['vendorGameId']), entry: BaishunLaunchEntryModel.fromJson( json['entry'] as Map? ?? const {}, ), bridgeConfig: BaishunBridgeConfigModel.fromJson( json['bridgeConfig'] as Map? ?? const {}, ), roomState: BaishunRoomStateModel.fromJson( json['roomState'] as Map? ?? const {}, ), ); } } 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; }