/// 事件过滤器（匹配指南 §8.4 subscribeEvents 规范）
class EventFilter {
  /// 订阅类型: 'newHeads' | 'logs'
  final String type;

  /// 合约地址（仅 logs 类型时使用）
  final String? address;

  /// 事件主题过滤（仅 logs 类型时使用）
  final List<String>? topics;

  const EventFilter({
    required this.type,
    this.address,
    this.topics,
  });

  /// 创建新区块订阅过滤器
  const EventFilter.newHeads()
      : type = 'newHeads',
        address = null,
        topics = null;

  /// 创建合约事件订阅过滤器
  const EventFilter.logs({this.address, this.topics}) : type = 'logs';

  /// 转换为 eth_subscribe 的 params
  Map<String, dynamic> get params {
    final p = <String, dynamic>{};
    if (address != null) p['address'] = address;
    if (topics != null) p['topics'] = topics;
    return p;
  }
}
