class DeviceReport {
  final String? deviceUuid;
  final int? startTime;
  final int? endTime;
  final List<DeviceEvent>? data;

  DeviceReport({
    this.deviceUuid,
    this.startTime,
    this.endTime,
    this.data,
  });

  DeviceReport.fromJson(Map<String, dynamic> json)
      : deviceUuid = json['deviceUuid'] as String?,
        startTime = int.tryParse(json['startTime'].toString()) ??
            json['startTime'] as int?,
        endTime =
            int.tryParse(json['endTime'].toString()) ?? json['endTime'] as int?,
        data = json['data'] != null
            ? (json['data'] as List<dynamic>?)
                ?.map((e) => DeviceEvent.fromJson(e as Map<String, dynamic>))
                .toList()
            : [];

  Map<String, dynamic> toJson() => {
        'deviceUuid': deviceUuid,
        'startTime': startTime,
        'endTime': endTime,
        'data': data?.map((e) => e.toJson()).toList(),
      };
}

class DeviceEvent {
  final String? code;
  final int? eventTime;
  final String? value;

  DeviceEvent({
    this.code,
    this.eventTime,
    this.value,
  });

  DeviceEvent.fromJson(Map<String, dynamic> json)
      : code = json['code'] as String?,
        eventTime = json['eventTime'] as int?,
        value = json['value'] as String?;

  Map<String, dynamic> toJson() => {
        'code': code,
        'eventTime': eventTime,
        'value': value,
      };
}
