formatPayload method

  1. @override
Map<String, dynamic> formatPayload(
  1. List<LogEntry> logs
)

Formats items into a JSON payload for the API. Subclasses must implement this to format their specific item types.

Implementation

@override
Map<String, dynamic> formatPayload(List<LogEntry> logs) {
  // Use new typed context from Voo.context (preferred)
  final context = Voo.context;
  if (context != null) {
    return {
      'logs': logs.map(_formatLogEntry).toList(),
      ...context.toSyncPayload(),
    };
  }

  // Fallback: Use LogEntry fields (backwards compatibility)
  final firstLog = logs.isNotEmpty ? logs.first : null;
  // API expects flat structure with logs array and batch-level metadata
  return {
    'logs': logs.map(_formatLogEntry).toList(),
    'sessionId': firstLog?.sessionId ?? '',
    'deviceId': firstLog?.deviceId ?? '',
    'platform': _getPlatform(),
    'appVersion': firstLog?.appVersion ?? '',
  };
}