import 'package:equatable/equatable.dart';

enum TradeType { buy, sell }

/// 成交记录实体（包含完整交易明细）
class TradeRecord extends Equatable {
  /// 成交ID
  final String id;
  /// 成交编号
  final String tradeNo;
  /// 交易类型
  final TradeType type;
  /// 成交价格
  final String price;
  /// 有效积分股（含销毁倍数）
  final String quantity;
  /// 原始卖出数量
  final String originalQuantity;
  /// 销毁数量
  final String burnQuantity;
  /// 销毁倍数
  final String burnMultiplier;
  /// 交易总额（扣除手续费前）
  final String grossAmount;
  /// 手续费（进入积分股池，卖方支付，买方为0）
  final String fee;
  /// 实际获得（扣除手续费后）
  final String netAmount;
  /// 对手方账号
  final String counterparty;
  /// 成交时间
  final DateTime createdAt;

  const TradeRecord({
    required this.id,
    required this.tradeNo,
    required this.type,
    required this.price,
    required this.quantity,
    required this.originalQuantity,
    required this.burnQuantity,
    required this.burnMultiplier,
    required this.grossAmount,
    required this.fee,
    required this.netAmount,
    required this.counterparty,
    required this.createdAt,
  });

  bool get isBuy => type == TradeType.buy;
  bool get isSell => type == TradeType.sell;

  /// 是否有手续费
  bool get hasFee {
    final feeValue = double.tryParse(fee) ?? 0;
    return feeValue > 0;
  }

  /// 是否有销毁倍数（大于1表示有销毁）
  bool get hasBurn {
    final multiplier = double.tryParse(burnMultiplier) ?? 1;
    return multiplier > 1;
  }

  @override
  List<Object?> get props => [id, tradeNo, type, price, quantity, fee];
}
