import 'dart:async';

import 'package:laki_icu_app/models/bo/bluetooth_read_model.dart';
import 'package:laki_icu_app/utils/bluetooth/index.dart';

class EventBus {
  final StreamController<dynamic> _controller = StreamController.broadcast();

  Stream<T> on<T>() {
    return _controller.stream.where((event) => event is T).cast<T>();
  }

  void emit(dynamic event) {
    _controller.add(event);
  }

  void dispose() {
    _controller.close();
  }
}

// 全局事件总线实例
final eventBus = EventBus();

// Token 过期事件
class TokenExpiredEvent {}

// 退出登录事件
class LogoutEvent {}

// 打开蓝牙扫描/绑定页面事件
class OpenBluetoothScanEvent {}

// 蓝牙读取信息更新事件
class BluetoothReadInfoChangedEvent {
  final BluetoothReadModel info;

  const BluetoothReadInfoChangedEvent(this.info);
}

// 蓝牙读取信息清空事件
class BluetoothReadInfoClearedEvent {
  const BluetoothReadInfoClearedEvent();
}

// MCU上报数据更新事件
class McuReportChangedEvent {
  final McuReport report;

  const McuReportChangedEvent(this.report);
}
