import 'market_history_four_hour_slot.dart'; /// One Alpaca backfill request bucket: a UTC 4-hour slot and its symbols. class BackfillSyncItem { const BackfillSyncItem({ required this.slotStart, required this.symbols, }); final DateTime slotStart; final List symbols; Map toJson() => { 'slotStart': MarketHistoryFourHourSlot.slotStartWire(slotStart), 'symbols': symbols, }; static BackfillSyncItem? tryFromJson(dynamic raw) { if (raw is! Map) { return null; } final String? slotStartRaw = raw['slotStart'] as String?; if (slotStartRaw == null) { return null; } final DateTime? slotStart = DateTime.tryParse(slotStartRaw)?.toUtc(); if (slotStart == null) { return null; } final List symbolRaw = raw['symbols'] as List? ?? []; final List symbols = symbolRaw .map((dynamic value) => value.toString()) .where((String value) => value.isNotEmpty) .toList(growable: false); return BackfillSyncItem(slotStart: slotStart, symbols: symbols); } static List listFromJson(dynamic raw) { if (raw == null) { return []; } if (raw is! List) { return []; } final List items = []; for (final dynamic entry in raw) { final BackfillSyncItem? item = tryFromJson(entry); if (item != null) { items.add(item); } } return items; } static List> encodeList(List items) { return items.map((BackfillSyncItem item) => item.toJson()).toList(); } }