import 'dart:convert'; /// Represents a dated reminder or to-do for the trip. class ReminderItem { /// Unique identifier. final String id; /// Text to display. final String title; /// Optional detailed note. final String? note; /// Due date/time (UTC) for the reminder. final DateTime dueAt; /// Completion flag. final bool isDone; /// Creation timestamp. final DateTime createdAt; /// Creates a reminder item. const ReminderItem({ required this.id, required this.title, required this.dueAt, required this.isDone, required this.createdAt, this.note, }); /// Convenience builder for new pending reminder. factory ReminderItem.newItem({ required String id, required String title, required DateTime dueAt, String? note, }) { return ReminderItem( id: id, title: title, note: note, dueAt: dueAt, isDone: false, createdAt: DateTime.now().toUtc(), ); } /// Copy with changes. ReminderItem copyWith({ String? id, String? title, String? note, DateTime? dueAt, bool? isDone, DateTime? createdAt, }) { return ReminderItem( id: id ?? this.id, title: title ?? this.title, note: note ?? this.note, dueAt: dueAt ?? this.dueAt, isDone: isDone ?? this.isDone, createdAt: createdAt ?? this.createdAt, ); } /// JSON serialization. Map toJson() { return { 'id': id, 'title': title, 'note': note, 'dueAt': dueAt.toIso8601String(), 'isDone': isDone, 'createdAt': createdAt.toIso8601String(), }; } /// JSON deserialization. factory ReminderItem.fromJson(Map json) { return ReminderItem( id: json['id'] as String, title: json['title'] as String, note: json['note'] as String?, dueAt: DateTime.parse(json['dueAt'] as String), isDone: json['isDone'] as bool? ?? false, createdAt: DateTime.parse(json['createdAt'] as String), ); } /// Encodes list. static String encodeList(List reminders) { return json.encode(reminders.map((r) => r.toJson()).toList()); } /// Decodes list. static List decodeList(String raw) { final decoded = json.decode(raw) as List; return decoded .cast>() .map(ReminderItem.fromJson) .toList(); } }