toJson method

Map<String, dynamic> toJson()

Converts this Observation to a JSON map.

Used for serializing observation data for API transmission or local storage. Converts camelCase field names to snake_case to match API expectations.

Implementation

Map<String, dynamic> toJson() {
  return {
    'id': id,
    'species_scientific_name': speciesScientificName,
    'count': count,
    'location': location.toJson(),
    'observed_at': observedAt.toIso8601String(),
    if (notes != null) 'notes': notes,
    if (userId != null) 'user_id': userId,
    if (locationAccuracyM != null) 'location_accuracy_m': locationAccuracyM,
    if (dataSource != null) 'data_source': dataSource,
    if (imageFilename != null) 'image_filename': imageFilename,
    if (modelId != null) 'model_id': modelId,
    if (confidence != null) 'confidence': confidence,
    if (metadata != null) 'metadata': metadata,
  };
}