// ignore_for_file: sort_constructors_first import 'package:flutter/foundation.dart'; /// Reminder cadence supported by the local scheduling layer. enum ReminderCadence { daily, weekly, monthly } /// Reminder rule stored locally and optionally synced later. @immutable class ReminderRule { const ReminderRule({ required this.id, required this.title, required this.cadence, required this.nextAt, this.personId, this.enabled = true, }); final String id; final String? personId; final String title; final ReminderCadence cadence; final DateTime nextAt; final bool enabled; ReminderRule copyWith({ String? id, String? personId, String? title, ReminderCadence? cadence, DateTime? nextAt, bool? enabled, }) { return ReminderRule( id: id ?? this.id, personId: personId ?? this.personId, title: title ?? this.title, cadence: cadence ?? this.cadence, nextAt: nextAt ?? this.nextAt, enabled: enabled ?? this.enabled, ); } Map toJson() { return { 'id': id, 'personId': personId, 'title': title, 'cadence': cadence.name, 'nextAt': nextAt.toUtc().toIso8601String(), 'enabled': enabled, }; } factory ReminderRule.fromJson(Map json) { final String cadenceName = json['cadence'] as String? ?? ReminderCadence.weekly.name; return ReminderRule( id: json['id'] as String, personId: json['personId'] as String?, title: json['title'] as String, cadence: ReminderCadence.values.firstWhere( (ReminderCadence cadence) => cadence.name == cadenceName, orElse: () => ReminderCadence.weekly, ), nextAt: DateTime.parse(json['nextAt'] as String).toLocal(), enabled: json['enabled'] as bool? ?? true, ); } }