/// 链上充值父币种 — GET uc/coin-network/recharge-parents
class RechargeParentCoin {
  final String name;
  final String nameCn;
  final String unit;
  final int status;
  final int canRecharge;
  final int sort;

  const RechargeParentCoin({
    required this.name,
    required this.nameCn,
    required this.unit,
    this.status = 0,
    this.canRecharge = 0,
    this.sort = 0,
  });

  factory RechargeParentCoin.fromJson(Map<String, dynamic> json) {
    return RechargeParentCoin(
      name: json['name']?.toString() ?? '',
      nameCn: json['nameCn']?.toString() ?? '',
      unit: json['unit']?.toString() ?? '',
      status: int.tryParse(json['status']?.toString() ?? '') ?? 0,
      canRecharge: int.tryParse(json['canRecharge']?.toString() ?? '') ?? 0,
      sort: int.tryParse(json['sort']?.toString() ?? '') ?? 0,
    );
  }
}

/// 扁平化后的充值网络选项（与 Web `RechargeFlatNetworkOption` 一致）
class RechargeFlatNetworkOption {
  final String coinName;
  final String coinNameCn;
  final int networkConfigId;
  final String networkName;
  final String protocol;
  final String contractAddress;
  final String rechargeAddress;

  const RechargeFlatNetworkOption({
    required this.coinName,
    required this.coinNameCn,
    required this.networkConfigId,
    required this.networkName,
    required this.protocol,
    required this.contractAddress,
    required this.rechargeAddress,
  });

  bool get hasTokenContract => contractAddress.trim().isNotEmpty;
}

/// 充值订单详情
class RechargeOrderDetail {
  final int id;
  final String orderNo;
  final String coinName;
  final String networkName;
  final String rechargeAddress;
  final String amount;
  final String? txHash;
  final int status;
  final String createTime;

  const RechargeOrderDetail({
    this.id = 0,
    this.orderNo = '',
    this.coinName = '',
    this.networkName = '',
    this.rechargeAddress = '',
    this.amount = '0',
    this.txHash,
    this.status = 0,
    this.createTime = '',
  });

  factory RechargeOrderDetail.fromJson(Map<String, dynamic> json) {
    final th = json['txHash'];
    return RechargeOrderDetail(
      id: int.tryParse(json['id']?.toString() ?? '') ?? 0,
      orderNo: json['orderNo']?.toString() ?? '',
      coinName: json['coinName']?.toString() ?? '',
      networkName: json['networkName']?.toString() ?? '',
      rechargeAddress: json['rechargeAddress']?.toString() ?? '',
      amount: json['amount']?.toString() ?? '0',
      txHash: th != null && th.toString().isNotEmpty ? th.toString() : null,
      status: int.tryParse(json['status']?.toString() ?? '') ?? 0,
      createTime: json['createTime']?.toString() ?? '',
    );
  }

  bool get isPendingPayment => status == 0;
}
