/// 资产流水记录 - POST uc/asset/transaction/all
class AssetStatement {
  final String id;
  final String fee;
  final String flag;
  final String type;
  final String amount;
  final String symbol;
  final String realFee;

  /// 返佣ID（JSON: address）
  final String rebateId;

  /// 用户ID（JSON: memberId）
  final String accountId;

  final String createTime;

  /// "0"=开仓 "1"=平仓
  final String direction;

  final String discountFee;

  const AssetStatement({
    this.id = '',
    this.fee = '0',
    this.flag = '0',
    this.type = '',
    this.amount = '0',
    this.symbol = '',
    this.realFee = '0',
    this.rebateId = '',
    this.accountId = '',
    this.createTime = '',
    this.direction = '',
    this.discountFee = '0',
  });

  /// type=1,19,25 时显示额外字段
  bool get showExtraField => ['1', '19', '25'].contains(type);

  String get displaySymbol => symbol;

  factory AssetStatement.fromJson(Map<String, dynamic> json) {
    return AssetStatement(
      id: json['id']?.toString() ?? '',
      fee: json['fee']?.toString() ?? '0',
      flag: json['flag']?.toString() ?? '0',
      type: json['type']?.toString() ?? '',
      amount: json['amount']?.toString() ?? '0',
      symbol: json['symbol']?.toString() ?? '',
      realFee: json['realFee']?.toString() ?? '0',
      rebateId: json['address']?.toString() ?? '',
      accountId: json['memberId']?.toString() ?? '',
      createTime: json['createTime']?.toString() ?? '',
      direction: json['direction']?.toString() ?? '',
      discountFee: json['discountFee']?.toString() ?? '0',
    );
  }
}

/// 流水类型 - GET uc/asset/transaction/type
class StatementType {
  final int index;

  /// 类型ID（JSON: typeName）
  final String typeId;

  final String name;

  const StatementType({
    this.index = 0,
    this.typeId = '',
    this.name = '',
  });

  factory StatementType.fromJson(Map<String, dynamic> json) {
    return StatementType(
      index: json['index'] as int? ?? 0,
      typeId: json['index']?.toString() ?? '',  // 后台用 ordinal 整数过滤，不是枚举名
      name: json['name']?.toString() ?? '',
    );
  }
}

/// 流水币种筛选项 - GET uc/asset/transaction/coin
class StatementCoin {
  final String fullName;
  final String code;
  final String name;
  final int sort;

  const StatementCoin({
    this.fullName = '',
    this.code = '',
    this.name = '',
    this.sort = 0,
  });

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