import '../utils/formatters.dart';

/// 地址余额
class AddressBalance {
  final String address;
  final BigInt balance;
  final int nonce;

  AddressBalance({
    required this.address,
    required this.balance,
    required this.nonce,
  });

  /// 格式化余额为 GNX（18 位小数）
  String get balanceInGnx => Formatters.formatGnx(balance);

  factory AddressBalance.fromJson(Map<String, dynamic> json) {
    return AddressBalance(
      address: json['address'] as String,
      balance: BigInt.parse(json['balance'].toString()),
      nonce: json['nonce'] as int,
    );
  }

  Map<String, dynamic> toJson() => {
        'address': address,
        'balance': balance.toString(),
        'nonce': nonce,
      };
}
