import '../../../core/api_gateway.dart'; import 'schedule_json.dart'; /// Weekday keys the server accepts for an interval rule. const scheduleDays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; /// The timer part of a saved schedule (`rule` on the wire). /// /// This is a view over the decoded server record, not a timer implementation: /// it never calculates due times, converts timezones or starts runs. Unknown /// rule fields stay in [raw] and are returned by [toJson]. class ScheduleRule { ScheduleRule([JsonMap? raw]) : raw = cloneJsonMap(raw ?? const {}); final JsonMap raw; /// Go-style duration such as `24h` or `1h30m`; empty for a clock rule. String get every => _text(raw['every']); /// Distinct 24-hour times such as `09:00`; empty for an interval rule. List get times => _texts(raw['times']); /// Empty means every day (written as absent on the wire). List get days => _texts(raw['days']); /// Empty or `Local` means the server's timezone. String get timezone => _text(raw['timezone']); bool get isClock => times.isNotEmpty; JsonMap toJson() => cloneJsonMap(raw); } String _text(dynamic value) => value is String ? value : ''; List _texts(dynamic value) => value is List ? [ for (final item in value) if (item is String) item, ] : const [];