import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_measure/utils/prompt_box.dart';
import 'package:flyinsono/architecture/router/router.dart';
import 'package:flyinsono/managers/interfaces/appointment_consultation.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/index.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/state.dart';
import 'package:get/get.dart';

class RealTimeConsultationVisitController {
  late final RealTimeConsultationController controller;
  late final RealTimeConsultationState state;
  final appointmentConsultationManager = Get.find<IAppointmentConsultation>();
  RealTimeConsultationVisitController(this.controller) {
    this.state = controller.state;
  }

  ///添加随访信息
  Future<void> addFollowUpVisitInfo(String? phone, String? visitRecord) async {
    if (visitRecord?.isEmpty ?? false) {
      PromptBox.toast(i18nBook.realTimeConsultation.pleaseWriteFollowUp.t);
      return;
    }
    var result = await appointmentConsultationManager.addFollowUpVisitInfo(
        phone,
        controller.state.consultationsRecordInfos.patientName ?? '',
        controller.state.currentConsultationCode,
        visitRecord);
    if (result) {
      PromptBox.toast(i18nBook.remedical.submitSuccess.t);
      router.back();
    }
  }

  ///获取会诊随访信息
  Future<List<FollowUpVisitDTO>> getFollowUpVisitInfo() async {
    controller.state.followUpVisistInfoList =
        await appointmentConsultationManager
            .getFollowUpVisitInfo(controller.state.currentConsultationCode);
    return controller.state.followUpVisistInfoList;
  }
}
