import '../../../core/utils/avatar_urls.dart';

/// 顶级交易员数据模型
class TopTrader {
  final String id;
  final String nickname;
  final String avatar;
  final double dayYield30; // 近14天收益率（来自 dayYield14 字段）
  final double profitAmount; // 近14天收益 USDT（与跟单列表 profit30d 同源）
  final int followCustomer;

  const TopTrader({
    this.id = '',
    required this.nickname,
    required this.avatar,
    required this.dayYield30,
    required this.profitAmount,
    this.followCustomer = 0,
  });

  factory TopTrader.fromJson(Map<String, dynamic> json) {
    double _d(String key) =>
        double.tryParse((json[key] ?? '0').toString()) ?? 0.0;
    return TopTrader(
      id: json['id']?.toString() ?? json['userId']?.toString() ?? '',
      nickname: json['nickname'] as String? ?? '',
      avatar:
          resolvedAvatarUrlFromRecord(Map<String, dynamic>.from(json)) ?? '',
      dayYield30: _d('dayYield14'),
      profitAmount: _d('profitAmount'),
      followCustomer: json['followCustomer'] as int? ?? 0,
    );
  }

  /// 头像首字母
  String get avatarLetter =>
      nickname.isNotEmpty ? nickname[0].toUpperCase() : 'T';
}
