Files
front-hokm/lib/feature/profile/data/model/profile_model.dart
T
2026-06-17 12:57:28 +03:30

36 lines
1.3 KiB
Dart

import '../../domain/entities/profile_entity.dart';
/// نگاشتِ پاسخ‌های /me، /wallet و /stats به ProfileEntity.
class ProfileModel {
static ProfileEntity fromJson(
Map<String, dynamic> user,
Map<String, dynamic> wallet,
Map<String, dynamic> stats,
) {
final name = (user['first_name'] as String?)?.trim();
final avatar = (user['avatar'] as String?)?.trim();
final s = stats['stats'] as Map?;
return ProfileEntity(
name: (name == null || name.isEmpty) ? 'بازیکن' : name,
avatar: (avatar == null || avatar.isEmpty) ? 'hakem-1' : avatar,
mobile: (user['mobile'] as String?) ?? '',
level: (wallet['level'] ?? 1) as int,
trophies: (wallet['trophies'] ?? 0) as int,
xpInto: (wallet['xp_into_level'] ?? 0) as int,
xpNext: (wallet['xp_for_next'] ?? 1) as int,
vip: (stats['vip'] ?? false) as bool,
stats: s == null
? null
: ProfileStats(
games: (s['games'] ?? 0) as int,
wins: (s['wins'] ?? 0) as int,
losses: (s['losses'] ?? 0) as int,
kotMade: (s['kot_made'] ?? 0) as int,
kotReceived: (s['kot_received'] ?? 0) as int,
cuts: (s['cuts'] ?? 0) as int,
hakemCount: (s['hakem_count'] ?? 0) as int,
),
);
}
}