import 'enums.dart'; class UserProfile { final int age; final Sex sex; final String country; final double heightCm; final double weightKg; final Set diagnoses; const UserProfile({ required this.age, required this.sex, required this.country, required this.heightCm, required this.weightKg, this.diagnoses = const {}, }); double get bmi => weightKg / ((heightCm / 100) * (heightCm / 100)); Map toJson() => { 'age': age, 'sex': sex.name, 'country': country, 'heightCm': heightCm, 'weightKg': weightKg, 'diagnoses': diagnoses.map((d) => d.name).toList(), }; factory UserProfile.fromJson(Map json) => UserProfile( age: json['age'] as int, sex: Sex.values.byName(json['sex'] as String), country: json['country'] as String, heightCm: (json['heightCm'] as num).toDouble(), weightKg: (json['weightKg'] as num).toDouble(), diagnoses: (json['diagnoses'] as List) .map((d) => Diagnosis.values.byName(d as String)) .toSet(), ); UserProfile copyWith({ int? age, Sex? sex, String? country, double? heightCm, double? weightKg, Set? diagnoses, }) => UserProfile( age: age ?? this.age, sex: sex ?? this.sex, country: country ?? this.country, heightCm: heightCm ?? this.heightCm, weightKg: weightKg ?? this.weightKg, diagnoses: diagnoses ?? this.diagnoses, ); }