/// 持仓汇总 — 对应后端 GET /api/v1/coupons/my/summary
class HoldingsSummaryModel {
  final int count;
  final double totalFaceValue;
  final double totalSaved;

  const HoldingsSummaryModel({
    required this.count,
    required this.totalFaceValue,
    required this.totalSaved,
  });

  factory HoldingsSummaryModel.fromJson(Map<String, dynamic> json) {
    return HoldingsSummaryModel(
      count: json['count'] ?? 0,
      totalFaceValue: _toDouble(json['totalFaceValue']),
      totalSaved: _toDouble(json['totalSaved']),
    );
  }

  static double _toDouble(dynamic value) {
    if (value == null) return 0;
    if (value is num) return value.toDouble();
    return double.tryParse(value.toString()) ?? 0;
  }
}
