class Supplement { final int? id; final String name; final double dosageAmount; // Amount per unit (e.g., 187mg) final int numberOfUnits; // Number of units to take (e.g., 2 capsules) final String unit; // mg, g, ml, etc. final String unitType; // capsules, tablets, ml, etc. final int frequencyPerDay; final List reminderTimes; // e.g., ['08:00', '20:00'] final String? notes; final DateTime createdAt; final bool isActive; Supplement({ this.id, required this.name, required this.dosageAmount, required this.numberOfUnits, required this.unit, required this.unitType, required this.frequencyPerDay, required this.reminderTimes, this.notes, required this.createdAt, this.isActive = true, }); // Helper getter for total dosage per intake double get totalDosagePerIntake => dosageAmount * numberOfUnits; Map toMap() { return { 'id': id, 'name': name, 'dosageAmount': dosageAmount, 'numberOfUnits': numberOfUnits, 'unit': unit, 'unitType': unitType, 'frequencyPerDay': frequencyPerDay, 'reminderTimes': reminderTimes.join(','), 'notes': notes, 'createdAt': createdAt.toIso8601String(), 'isActive': isActive ? 1 : 0, }; } factory Supplement.fromMap(Map map) { return Supplement( id: map['id'], name: map['name'], dosageAmount: map['dosageAmount']?.toDouble() ?? map['dosage']?.toDouble() ?? 0.0, // Backwards compatibility numberOfUnits: map['numberOfUnits'] ?? 1, // Default to 1 for backwards compatibility unit: map['unit'], unitType: map['unitType'] ?? 'units', // Default unit type for backwards compatibility frequencyPerDay: map['frequencyPerDay'], reminderTimes: map['reminderTimes'].split(','), notes: map['notes'], createdAt: DateTime.parse(map['createdAt']), isActive: map['isActive'] == 1, ); } Supplement copyWith({ int? id, String? name, double? dosageAmount, int? numberOfUnits, String? unit, String? unitType, int? frequencyPerDay, List? reminderTimes, String? notes, DateTime? createdAt, bool? isActive, }) { return Supplement( id: id ?? this.id, name: name ?? this.name, dosageAmount: dosageAmount ?? this.dosageAmount, numberOfUnits: numberOfUnits ?? this.numberOfUnits, unit: unit ?? this.unit, unitType: unitType ?? this.unitType, frequencyPerDay: frequencyPerDay ?? this.frequencyPerDay, reminderTimes: reminderTimes ?? this.reminderTimes, notes: notes ?? this.notes, createdAt: createdAt ?? this.createdAt, isActive: isActive ?? this.isActive, ); } }