class Habit { const Habit({ required this.id, required this.title, required this.createdAt, required this.completedDates, }); final String id; final String title; final DateTime createdAt; final Set completedDates; Habit copyWith({String? title, Set? completedDates}) { return Habit( id: id, title: title ?? this.title, createdAt: createdAt, completedDates: completedDates ?? this.completedDates, ); } Map toJson() { return { 'id': id, 'title': title, 'createdAt': createdAt.toIso8601String(), 'completedDates': completedDates.toList()..sort(), }; } static Habit fromJson(Map json) { return Habit( id: json['id'] as String, title: json['title'] as String, createdAt: DateTime.parse(json['createdAt'] as String), completedDates: ((json['completedDates'] as List?) ?? const []) .map((value) => value.toString()) .toSet(), ); } }