import 'package:flyinsono/managers/interfaces/remedical.dart';
import 'package:flyinsono/managers/interfaces/report.dart';
import 'package:flyinsono/pages/remedical/consultation_record_view/controller.dart';
import 'package:flyinsono/pages/remedical/consultation_record_view/state.dart';
import 'package:get/get.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_ui/index.dart';
import 'package:fis_measure/process/workspace/rpc_bridge.dart';

class RemedicalController {
  final reportManager = Get.find<IReportManager>();
  final remedicalManager = Get.find<IRemedicalManager>();
  final ConsultationRecordViewController controller;

  ConsultationRecordViewState get state => controller.state;
  String get recordCode => controller.currentRecordData?.recordCode ?? '';
  String get patientCode => controller.currentRecordData?.patientCode ?? '';
  RemedicalController(this.controller) {
    if (kIsMobile) {
      reportManager.onMobileSubmitReport.addListener(_onMobileSubmitReport);
    }
  }

  void clear() {
    state.measureImages.clear();
    state.aiImages.clear();
    state.reports.clear();
  }

  void dispose() {
    reportManager.onMobileSubmitReport.removeListener(_onMobileSubmitReport);
  }

  void onSubmitReport(Object sender, bool e) {
    controller.changeTypeFilter(controller.typeFilter);
  }

  void _onMobileSubmitReport(Object sender, bool e) {
    controller.refreshData();
  }
}
