class CurrencyRate {
  final int id;
  final String currency;
  final String symbol;
  final double rate;
  final int coinPrecision;

  const CurrencyRate({
    required this.id,
    required this.currency,
    required this.symbol,
    required this.rate,
    required this.coinPrecision,
  });

  factory CurrencyRate.fromJson(Map<String, dynamic> json) {
    return CurrencyRate(
      id: (json['id'] as num?)?.toInt() ?? 0,
      currency: json['currency'] as String? ?? '',
      symbol: json['symbol'] as String? ?? '\$',
      rate: double.tryParse(json['rate']?.toString() ?? '') ?? 1.0,
      coinPrecision: (json['coinPrecision'] as num?)?.toInt() ?? 2,
    );
  }

  String get displayName => '$currency  $symbol';
}
