/// 心电检测数据
class TwelveHeartExamData {
  /// 心率
  final int heartRate;

  /// ECG波点集合
  final List<int> ecgPoints;

  TwelveHeartExamData({
    required this.heartRate,
    required this.ecgPoints,
  });

  factory TwelveHeartExamData.fromEventData(Map<String, dynamic> jsonMap) {
    final pointList = (jsonMap["POINT"] as List).map((e) => e as int).toList();
    return TwelveHeartExamData(
      heartRate: jsonMap["HR"],
      ecgPoints: pointList,
    );
  }
}

/// 心电检测结果
class TwelveHeartExamResult extends TwelveHeartExamData {
  /// 分析结果
  final TwelveHeartResultEntity resultConclusion;

  TwelveHeartExamResult({
    required this.resultConclusion,
    required super.ecgPoints,
    required super.heartRate,
  });

  factory TwelveHeartExamResult.fromEventData(Map<String, dynamic> jsonMap) {
    final resultConclusion =
        TwelveHeartResultEntity.fromJson(jsonMap["RESULTCONCLUSION"]);

    return TwelveHeartExamResult(
      heartRate: jsonMap["HR"],
      resultConclusion: resultConclusion,
      ecgPoints: [], //TODO: 暂不返回总点阵
    );
  }
}

class TwelveHeartResultEntity {
  ///自动分析结论，可能存在多条，以;间隔
  String advice;

  ///自动分析结论索引，与 Advice 内容一一对应，可能存在多条，以;间隔
  int index;

  ///心率
  String HR;

  ///PR间期
  String PR;

  ///P时限
  String PDur;

  ///QRS时限
  String QRSDur;

  ///T时限
  String TDur;

  ///QT间期
  String QTDur;

  ///QTc矫正后的QT间期
  String QTCDur;

  /// QT/QTC的值
  String QT_QTC_Dur;

  ///P波电轴
  String PAxis;

  ///QRS电轴
  String QRSAxis;

  ///T电轴
  String TAxis;

  /// P/QRS/T轴的值
  String P_QRS_T_Axis;

  /// R(V5)/S(V1) V5 导联R波的振幅/V1导联S波的振幅
  String Rv5_Sv1_1;

  ///R(V5)+S(V1) V5 导联R波的振幅+V1导联S波的振幅
  String Rv5_Sv1_2;

  ///基线滤波
  String baselineFiltering;

  ///肌电滤波
  String eMGFiltering;

  ///AC
  String ac;

  ///工频虑波
  String powerLineFiltering;

  ///纸速
  String paperSpeed;

  ///增益
  String gain;

  TwelveHeartResultEntity({
    required this.advice,
    required this.index,
    required this.HR,
    required this.PR,
    required this.PDur,
    required this.QRSDur,
    required this.TDur,
    required this.QTDur,
    required this.QTCDur,
    required this.QT_QTC_Dur,
    required this.PAxis,
    required this.QRSAxis,
    required this.TAxis,
    required this.P_QRS_T_Axis,
    required this.Rv5_Sv1_1,
    required this.Rv5_Sv1_2,
    this.baselineFiltering = "1.6",
    this.eMGFiltering = "53Hz",
    this.ac = "AC",
    this.powerLineFiltering = "50Hz",
    this.paperSpeed = "25mm/s",
    this.gain = "5mm/mV",
  });

  factory TwelveHeartResultEntity.fromJson(Map<String, dynamic> json) {
    return TwelveHeartResultEntity(
      advice: json['advice'],
      index: json['index'],
      HR: json['HR'],
      PR: json['PR'],
      PDur: json['PDur'],
      QRSDur: json['QRSDur'],
      TDur: json['TDur'],
      QTDur: json['QTDur'],
      QTCDur: json['QTCDur'],
      QT_QTC_Dur: json['QT_QTC_Dur'],
      PAxis: json['PAxis'],
      QRSAxis: json['QRSAxis'],
      TAxis: json['TAxis'],
      P_QRS_T_Axis: json['P_QRS_T_Axis'],
      Rv5_Sv1_1: json['Rv5_Sv1_1'],
      Rv5_Sv1_2: json['Rv5_Sv1_2'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'advice': advice,
      'index': index,
      'HR': HR,
      'PR': PR,
      'PDur': PDur,
      'QRSDur': QRSDur,
      'TDur': TDur,
      'QTDur': QTDur,
      'QTCDur': QTCDur,
      'QT_QTC_Dur': QT_QTC_Dur,
      'PAxis': PAxis,
      'QRSAxis': QRSAxis,
      'TAxis': TAxis,
      'P_QRS_T_Axis': P_QRS_T_Axis,
      'Rv5_Sv1_1': Rv5_Sv1_1,
      'Rv5_Sv1_2': Rv5_Sv1_2,
      "BaselineFiltering": baselineFiltering,
      "EMGFiltering": eMGFiltering,
      "AC": ac,
      "PowerLineFiltering": powerLineFiltering,
      "PaperSpeed": paperSpeed,
      "Gain": gain,
    };
  }
}
