import 'package:equatable/equatable.dart';

/// 用户资产显示信息
/// 来自后端 trading-service 的 /asset/my 或 /asset/account/:accountSequence 接口
/// 汇总了挖矿账户和交易账户的数据
class AssetDisplay extends Equatable {
  /// 挖矿账户积分股余额
  final String miningShareBalance;

  /// 交易账户积分股余额
  final String tradingShareBalance;

  /// 总积分股余额（挖矿 + 交易）
  final String shareBalance;

  /// 账户现金余额（交易账户）
  final String cashBalance;

  /// 冻结积分股
  final String frozenShares;

  /// 冻结现金
  final String frozenCash;

  /// 可用积分股
  final String availableShares;

  /// 可用现金
  final String availableCash;

  /// 当前价格
  final String currentPrice;

  /// 销毁倍数
  final String burnMultiplier;

  /// 有效积分股（含销毁加成）
  final String effectiveShares;

  /// 资产显示值 = (账户积分股 + 账户积分股 × 倍数) × 积分股价
  final String displayAssetValue;

  /// 每秒增长量
  final String assetGrowthPerSecond;

  /// 累计买入
  final String totalBought;

  /// 累计卖出
  final String totalSold;

  const AssetDisplay({
    required this.miningShareBalance,
    required this.tradingShareBalance,
    required this.shareBalance,
    required this.cashBalance,
    required this.frozenShares,
    required this.frozenCash,
    required this.availableShares,
    required this.availableCash,
    required this.currentPrice,
    required this.burnMultiplier,
    required this.effectiveShares,
    required this.displayAssetValue,
    required this.assetGrowthPerSecond,
    required this.totalBought,
    required this.totalSold,
  });

  /// 交易账户可用积分股（扣除冻结部分）= 总可用积分股 - 挖矿账户可用积分股
  String get tradingAvailableShares {
    final totalAvailable = double.tryParse(availableShares) ?? 0;
    final miningAvailable = double.tryParse(miningShareBalance) ?? 0;
    final result = totalAvailable - miningAvailable;
    return result < 0 ? '0' : result.toStringAsFixed(8);
  }

  /// 总积分股余额 = 可用 + 冻结
  String get totalShareBalance {
    final available = double.tryParse(availableShares) ?? 0;
    final frozen = double.tryParse(frozenShares) ?? 0;
    return (available + frozen).toString();
  }

  /// 总现金余额 = 可用 + 冻结
  String get totalCashBalance {
    final available = double.tryParse(availableCash) ?? 0;
    final frozen = double.tryParse(frozenCash) ?? 0;
    return (available + frozen).toString();
  }

  @override
  List<Object?> get props => [
        miningShareBalance,
        tradingShareBalance,
        shareBalance,
        cashBalance,
        frozenShares,
        frozenCash,
        availableShares,
        availableCash,
        currentPrice,
        burnMultiplier,
        effectiveShares,
        displayAssetValue,
        assetGrowthPerSecond,
        totalBought,
        totalSold,
      ];
}
