/// 链统计信息
class ChainStats {
  final int blockHeight;
  final int peerCount;
  final int chainId;
  final double? tps;
  final int? activeAddresses;
  final int? totalCoupons;
  final BigInt? totalVolume;

  ChainStats({
    required this.blockHeight,
    required this.peerCount,
    required this.chainId,
    this.tps,
    this.activeAddresses,
    this.totalCoupons,
    this.totalVolume,
  });

  factory ChainStats.fromJson(Map<String, dynamic> json) {
    return ChainStats(
      blockHeight: json['blockHeight'] as int,
      peerCount: json['peerCount'] as int,
      chainId: json['chainId'] as int,
      tps: json['tps'] as double?,
      activeAddresses: json['activeAddresses'] as int?,
      totalCoupons: json['totalCoupons'] as int?,
      totalVolume: json['totalVolume'] != null
          ? BigInt.parse(json['totalVolume'].toString())
          : null,
    );
  }

  Map<String, dynamic> toJson() => {
        'blockHeight': blockHeight,
        'peerCount': peerCount,
        'chainId': chainId,
        if (tps != null) 'tps': tps,
        if (activeAddresses != null) 'activeAddresses': activeAddresses,
        if (totalCoupons != null) 'totalCoupons': totalCoupons,
        if (totalVolume != null) 'totalVolume': totalVolume.toString(),
      };
}
