import 'dart:developer';

import 'package:hmg_patient_app_new/core/utils/date_util.dart';

class WeightMeasurementResult {
  int? patientID;
  int? lineItemNo;
  int? weightMeasured;
  DateTime? weightDate;
  dynamic remark;
  bool? isActive;
  int? measured;
  dynamic unit;
  int? chartYear;
  dynamic chartMonth;
  double? yearAverageResult;
  dynamic monthAverageResult;
  dynamic weekAverageResult;
  dynamic weekDesc;

  WeightMeasurementResult(
      {this.patientID,
      this.lineItemNo,
      this.weightMeasured,
      this.weightDate,
      this.remark,
      this.isActive,
      this.measured,
      this.unit,
      this.chartYear,
      this.chartMonth,
      this.yearAverageResult,
      this.monthAverageResult,
      this.weekAverageResult,
      this.weekDesc});

  WeightMeasurementResult.fromJson(Map<String, dynamic> json) {
    try {
      patientID = json['PatientID'];
      lineItemNo = json['LineItemNo'];
      weightMeasured = json['WeightMeasured'];
      weightDate = DateUtil.convertStringToDate(json['WeightDate']);
      remark = json['Remark'];
      isActive = json['IsActive'];
      measured = json['Measured'];
      unit = json['Unit'];
      chartYear = json['ChartYear'];
      chartMonth = json['ChartMonth'];
      // Convert to double safely since API may return int
      yearAverageResult = json['YearAverageResult'] != null ? (json['YearAverageResult'] as num).toDouble() : null;
      monthAverageResult = json['MonthAverageResult'];
      weekAverageResult = json['WeekAverageResult'];
      weekDesc = json['WeekDesc'];
    } catch (e) {
      log(e.toString());
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['PatientID'] = patientID;
    data['LineItemNo'] = lineItemNo;
    data['WeightMeasured'] = weightMeasured;
    data['WeightDate'] = weightDate;
    data['Remark'] = remark;
    data['IsActive'] = isActive;
    data['Measured'] = measured;
    data['Unit'] = unit;
    data['ChartYear'] = chartYear;
    data['ChartMonth'] = chartMonth;
    data['YearAverageResult'] = yearAverageResult;
    data['MonthAverageResult'] = monthAverageResult;
    data['WeekAverageResult'] = weekAverageResult;
    data['WeekDesc'] = weekDesc;
    return data;
  }
}
