import 'package:fis_jsonrpc/services/appletAPI.m.dart';
import 'package:flyinsono/architecture/router/mobile/names.dart';
import 'package:get/get.dart';

import 'index.dart';

// 预约会诊详情页（没有单独接口，数据来自外部的分页）
class WxConsultationDetailController extends GetxController {
  WxConsultationDetailController();

  final state = WxConsultationDetailState();

  String consultationId = '';

  // tap
  void handleStartConsultation() {
    Get.toNamed(MobileRouteNames.Wechat.MiniProgramConsultationRoom,
        arguments: consultationId);
  }

  // 获取arguements并写入
  void getRouteArgs() {
    final info = Get.arguments;
    if (info is ConsultationInfo) {
      consultationId = info.consultationId ?? '';
      state.name = info.patientName ?? '';
      state.age = info.patientAge ?? '';
      state.sex = _getSexText(info.patientSex);
      state.birthday = info.birthday.toString().substring(0, 10);
      state.mobile = info.contactInfo ?? '';
      state.id = info.patientID ?? '';
      state.pastMedicalHistory = info.history ?? '';
      state.preliminaryDiagnosis = info.primaryDiagnosis ?? '';
      state.consultationHospital = info.hospitalName ?? '';
      state.consultationExpert = info.expertName ?? '';
      state.applicationHospital = info.applyHospitalName ?? '';
      state.scanningDoctor = info.scanDoctorName ?? '';
      state.consultationDate =
          info.consultationDate.toString().substring(0, 10);
      state.examinationSite = info.inspectionItems ?? '';
      state.equipmentModel = info.deviceModel ?? '';
    } else {
      print("get Args: $info");
    }
  }

  String _getSexText(PatientGenderEnum sex) {
    switch (sex) {
      case PatientGenderEnum.Male:
        return '男';
      case PatientGenderEnum.Female:
        return '女';
      case PatientGenderEnum.NotFilled:
        return '未填写';
    }
  }

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
    getRouteArgs();
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
