class DeviceHealthSnapshot {
  const DeviceHealthSnapshot({
    this.batteryLevelPercent,
    required this.storageAvailablePercent,
  });

  factory DeviceHealthSnapshot.fromMap(Map<Object?, Object?> map) {
    final batteryRaw = map['batteryLevelPercent'];
    int? batteryLevelPercent;
    if (batteryRaw is int) {
      batteryLevelPercent = batteryRaw;
    } else if (batteryRaw is num) {
      batteryLevelPercent = batteryRaw.round();
    }

    final storageRaw = map['storageAvailablePercent'];
    final storageAvailablePercent = switch (storageRaw) {
      final num value => value.toDouble(),
      _ => 100.0,
    };

    return DeviceHealthSnapshot(
      batteryLevelPercent: batteryLevelPercent,
      storageAvailablePercent: storageAvailablePercent,
    );
  }

  final int? batteryLevelPercent;
  final double storageAvailablePercent;
}
