import '../../domain/entities/wallet_entity.dart';

/// مدلِ کیف‌پول؛ از پاسخِ /wallet و /me ساخته می‌شود.
class WalletModel extends WalletEntity {
  const WalletModel({
    required super.coins,
    required super.tickets,
    required super.xp,
    required super.trophies,
    required super.level,
    required super.xpIntoLevel,
    required super.xpForNext,
    required super.vip,
    required super.selectedCard,
    required super.selectedCarpet,
    super.selectedCarpetImg,
    required super.name,
    required super.avatar,
    super.avatarImg,
    super.dailyStreak,
    super.bestStreak,
    super.dailyReady,
    super.nextDaily,
  });

  factory WalletModel.fromJson(
    Map<String, dynamic> wallet,
    Map<String, dynamic> user,
  ) {
    final name = (user['first_name'] as String?)?.trim();
    final avatar = (user['avatar'] as String?)?.trim();
    return WalletModel(
      coins: (wallet['coins'] ?? 0) as int,
      tickets: (wallet['tickets'] ?? 0) as int,
      xp: (wallet['xp'] ?? 0) as int,
      trophies: (wallet['trophies'] ?? 0) as int,
      level: (wallet['level'] ?? 1) as int,
      xpIntoLevel: (wallet['xp_into_level'] ?? 0) as int,
      xpForNext: (wallet['xp_for_next'] ?? 1) as int,
      vip: (wallet['vip'] ?? false) as bool,
      selectedCard: (wallet['selected_card'] ?? 'simple') as String,
      selectedCarpet: (wallet['selected_carpet'] ?? 'classic') as String,
      selectedCarpetImg: (wallet['selected_carpet_img'] ?? '') as String,
      name: (name == null || name.isEmpty) ? 'بازیکن' : name,
      avatar: (avatar == null || avatar.isEmpty) ? 'hakem-1' : avatar,
      avatarImg: (wallet['selected_avatar_img'] ?? '') as String,
      dailyStreak: (wallet['daily_streak'] ?? 0) as int,
      bestStreak: (wallet['best_streak'] ?? 0) as int,
      dailyReady: (wallet['daily_ready'] ?? true) as bool,
      nextDaily: (wallet['next_daily'] ?? 200) as int,
    );
  }
}
