import 'package:fis_jsonrpc/rpc.dart';
import 'package:flyinsono/notifications/handlers/consulation/cancel_inviting_in_live_course_notification.dart';
import 'package:flyinsono/notifications/handlers/consulation/device_parameters_notification.dart';
import 'package:flyinsono/notifications/handlers/consulation/send_interactive_board_data_handler.dart';
import 'package:flyinsono/notifications/handlers/consulation/upload_consultation_data_handler.dart';
import 'package:flyinsono/notifications/handlers/lab/disk_space_notification_handler.dart';
import 'package:flyinsono/notifications/handlers/remote/connect_status_to_client_notification.dart';
import 'package:flyinsono/notifications/handlers/remote/device_disconnect_remote_control_notification_handler.dart';
import 'package:flyinsono/notifications/handlers/remote/device_download_patch_progress_to_user_notification_handler.dart';
import 'package:flyinsono/notifications/handlers/remote/device_printer_result_notification_handler.dart';
import 'package:flyinsono/notifications/handlers/remote/device_reject_remote_control_notification_handler.dart';
import 'package:flyinsono/notifications/handlers/remote/get_remote_log_to_client_handler.dart';
import 'package:flyinsono/notifications/handlers/remote/probe_application_setting_response_notification_handler.dart';
import 'package:flyinsono/notifications/handlers/remote/send_result_to_client_notification_handler.dart';
import 'package:flyinsono/notifications/handlers/schedule/Invitee_reject_apply_handler.dart';
import 'package:flyinsono/notifications/handlers/schedule/applay_handler.dart';
import 'package:flyinsono/notifications/handlers/schedule/approval_apply_handler.dart';
import 'package:flyinsono/notifications/handlers/schedule/invitee_approve_apply_handler.dart';
import 'package:flyinsono/notifications/handlers/schedule/invitee_approve_handler.dart';
import 'package:flyinsono/notifications/handlers/schedule/reject_apply_handler.dart';
import 'package:flyinsono/notifications/handlers/upgrade/upgrade_notification.dart';
import 'package:flyinsono/notifications/handlers/wechat/accept_meeting_handle.dart';
import 'package:flyinsono/notifications/handlers/wechat/meeting_hangup_handle.dart';
import 'package:flyinsono/notifications/handlers/wechat/reject_meeting_handle.dart';
import 'package:get/get.dart';

import 'handlers/college/change_share_live_course_handler.dart';
import 'handlers/college/index.dart';
import 'handlers/college/leave_course_handler.dart';
import 'handlers/college/live_interactive_board_data_notification.dart';
import 'handlers/consulation/accept_handler.dart';
import 'handlers/consulation/answer_timeout_handler.dart';
import 'handlers/consulation/cancel_handler.dart';
import 'handlers/consulation/cancel_inviting_in_live_handler.dart';
import 'handlers/consulation/change_consultation.dart';
import 'handlers/consulation/close_consultation_handler.dart';
import 'handlers/consulation/close_handler.dart';
import 'handlers/consulation/emergency_call_failed_handler.dart';
import 'handlers/consulation/emergency_call_handler.dart';
import 'handlers/consulation/invite_handler.dart';
import 'handlers/consulation/invite_in_live_handler.dart';
import 'handlers/consulation/join_handlers.dart';
import 'handlers/consulation/join_in_consultation.dart';
import 'handlers/consulation/leave_handler.dart';
import 'handlers/consulation/member_heart_rate_join_handler.dart';
import 'handlers/consulation/member_leave_handler.dart';
import 'handlers/consulation/mute_handler.dart';
import 'handlers/consulation/neterror_handler.dart';
import 'handlers/consulation/reject_handler.dart';
import 'handlers/consulation/reject_invite_live_handler.dart';
import 'handlers/consulation/switch_video_play.dart';
import 'handlers/execute_result_handler.dart';
import 'handlers/lab/task_completed_handler.dart';
import 'handlers/other_platform_notification_handler.dart';
import 'handlers/remote/save_and_exit_notification.dart';
import 'handlers/schedule/remind_handler.dart';
import 'handlers/token_replaced_handler.dart';

final _instance = _buildInstance();

/// 消息中心
WsNotificationCenter get notificationCenter => _instance;

// void runDistributeDemo() {
//   Future.delayed(
//     const Duration(milliseconds: 100),
//     () {
//       final handler = Get.find<TokenReplacedNotificationHandler>();
//       void onSub01(TokenReplacedNotification message) {
//         print("Sub01 - Receive msg at ${DateTime.now()}");
//       }

//       void onSub02(TokenReplacedNotification message) {
//         print("Sub02 - Receive msg at ${DateTime.now()}");
//         Future.delayed(const Duration(milliseconds: 100), () {
//           handler.unsubscribe(onSub02);
//         });
//       }

//       handler.subscribe(onSub01);
//       handler.subscribe(onSub02);
//     },
//   );
// }

WsNotificationCenter _buildInstance() {
  final instance = WsNotificationCenter();
  // 注册消息处理器
  instance.register(
      Get.put(SendInteractiveBoardDataHandler())); // 白板 | 1 | 互动白板数据通知
  instance.register(Get.put(TokenReplacedNotificationHandler()));
  instance.register(Get.put(
      CancelInvitingInLiveConsultationHandler())); // 7 |  取消会诊过程中邀请成员的通知
  instance
      .register(Get.put(InviteInLiveConsultationHandler())); // 8 |会诊过程中邀请成员的通知
  instance.register(
      Get.put(InviteLiveConsultationNotificationHandler())); //11 | 开始会诊的通知
  instance.register(
      Get.put(AcceptLiveConsultationNotificationHandler())); //12 | 接受会诊的通知
  instance.register(Get.put(RejectLiveConsultationHandler())); //13 | 拒绝会诊通知
  instance
      .register(Get.put(RejectInviteLiveConsultationHandler())); //21 | 拒绝会诊通知
  instance.register(
      Get.put(CancelLiveConsultationNotificationHandler())); // 15 | 取消会诊通知
  instance.register(
      Get.put(CloseLiveConsultationNotificationHandler())); // 16 | 关闭会诊通知
  instance.register(
      Get.put(JoinLiveConsultationNotificationHandler())); // 17 | 进入会诊通知
  instance.register(
      Get.put(NetworkErrConsultationNotificationHandler())); // 18 | 网络质量不佳的通知
  instance
      .register(Get.put(LeaveConsultationNotificationHandler())); // 19 离开会诊通知
  instance.register(
      Get.put(JoinInLiveConsultationNotificationHandler())); // 20 会诊中其他成员加入房间通知
  instance.register(Get.put(MuteLiveConsultationHandler())); // 27 成员静音通知
  instance.register(
      Get.put(SwitchVideoPlayConsultationHandler())); // 28 成员摄像头开启或关闭通知

  instance
      .register(Get.put(HeartRateJoinConsultationHandler())); // 29 成员心跳进入会诊间
  instance.register(
      Get.put(ConnectStatusToClientNotificationHandler())); // 72 远程连接客户端
  instance.register(
      Get.put(GetRemoteLogToClientNotificationHandler())); // 未知 远程获取超声机日志
  instance.register(Get.put(
      DeviceDownloadPatchProgressToUserNotificationHandler())); // 81 推送包进度
  instance.register(Get.put(
      DevicePrinterResultNotificationHandler())); // 未知 获取到设置打印机驱动时超声机的通知
  instance.register(Get.put(
      DeviceRejectRemoteControlNotificationHandler())); // 66 设备端没开启远程控制给到的通知

  instance.register(Get.put(
      DeviceDisconnectRemoteControlNotificationHandler())); // 67 获取到设备端断开的通知
  instance.register(
      Get.put(SendResultToClientNotificationHandler())); // 79 发送远程维护结果给客户端
  instance.register(Get.put(
      ProbeApplicationSettingResponseNotificationHandler())); // 88 收到设备端发送的探头通知

  instance.register(Get.put(EmergencyCallNotificationHandler())); //37 急诊呼叫专家通知
  instance.register(
      Get.put(EmergencyCallFailedNotificationHandler())); //38 急诊呼叫失败通知
  instance.register(Get.put(HeartRateLeaveConsultationHandler())); //30 成员离开通知
  instance
      .register(Get.put(ChangeConsultationNotificationHandler())); //52 切换会诊房间
  instance.register(
      Get.put(CloseConsultationDueToChangeNotificationHandler())); //55 关闭会诊房间
  instance
      .register(Get.put(ExecuteResultNotificationHandler())); // 77 导出测量数据结果通知
  instance.register(
      Get.put(RejectApplayNotificationHandler())); // 📅| 6 | 拒绝预约申请的通知
  instance.register(
      Get.put(ConsultationRemindNotificationHandler())); // 📅| 9 | 会诊开始前提醒的通知
  instance.register(Get.put(ApplyConsultationHandler())); // 📅| 22 | 会诊申请通知
  instance.register(
      Get.put(ApprovalApplyConsultationHandler())); // 📅| 23 | 批准申请会诊通知
  instance.register(
      Get.put(InviteeConsultationNotificationHandler())); // 📅| 24 | 会诊受邀请人通知
  instance.register(Get.put(
      InviteeApproveApplyConsultationNotificationHandler())); // 📅| 25 | 会诊受邀请参与人同意通知
  instance.register(
      Get.put(InviteeRejectNotificationHandler())); // 📅| 26 | 会诊受邀请参与人拒绝通知

  instance.register(
      Get.put(DeviceParametersNotificationHandler())); // 35 客户端收到 设备探头应用和参数信息
  //课程相关通知
  instance.register(Get.put(
      CancelInvitingInLiveCourseNotificationHandler())); // 68 取消呼叫 to 客户端
  instance.register(Get.put(InviteLiveCourseHandler())); // 39 课程开始通知
  instance.register(Get.put(JoinLiveCourseHandler())); // 40 加入课程通知
  instance.register(Get.put(HeartRateJoinCourseHandler())); // 42 加入直播课心跳通知
  instance.register(Get.put(NetworkErrCourseHandler())); // 43 直播课程网络异常通知
  instance.register(Get.put(CancelLiveCourseHandler())); // 44 取消直播课通知
  instance.register(Get.put(MuteLiveCourseHandler())); // 45 开启或者关闭声音通知
  instance.register(Get.put(CloseLiveCourseHandler())); // 47 结束直播通知
  instance.register(Get.put(HeartRateLeaveCourseHandler())); // 49 离线直播心跳通知
  instance.register(Get.put(LeaveLiveCourseHandler())); //50 课程成员离开
  instance.register(Get.put(SwitchLiveCourseVideoHandler())); // 51 开启或者关闭直播视频通知
  instance.register(Get.put(CourcePaySuccessHandler())); // 54 课程支付成功通知
  instance.register(Get.put(CourseStatusHandler())); // 57 审核课程状态通知
  instance.register(Get.put(UpgradeNotificationHandler())); // 58 更新通知
  instance.register(Get.put(SendLiveInteractiveBoardDataHandler())); // 58 更新通知
  instance.register(Get.put(ChangeShareInLiveCourseHandler())); // 58 更新通知
  instance.register(Get.put(ChangeShareInLiveCourseHandler())); // 97 共享信息改变通知
  instance
      .register(Get.put(OtherPlatformNotificationHandler())); // 98 来自其他平台通知信息

  instance.register(Get.put(UploadConsultationDataHandler())); // 103 会诊截图通知

  // 小程序相关通知
  instance
      .register(Get.put(MeetingHangupNotificationHandler())); // 90 | 小程序会诊挂断通知
  instance
      .register(Get.put(RejectMeetingNotificationHandler())); // 91 | 小程序会诊拒绝通知
  instance.register(
      Get.put(AcceptMeetingNotificationHandler())); // 93 | 发起者收到对方接受通知
  instance
      .register(Get.put(ConsultationAnswerTimeoutHandler())); // 100 | 超时未接听通知
  instance.register(Get.put(
      SaveAndExitToClientNotificationHandler())); // 101 | 	系统设置保存并退出结果通知 to 客户端，等到这个通知，页面才能关闭
  // runDistributeDemo();
  instance.register(Get.put(TaskCompletedNotificationHandler())); //任务完成通知
  instance.register(Get.put(DiskSpaceFullNotificationHandler())); //磁盘空间不足通知
  return instance;
}
