toJson method
Serializes FeedbackDraft to a JSON payload ready for POST /api/v1/feedback.
Injects SDK branding, platform wire value, and ISO 8601 submission timestamp into metadata.
Implementation
Map<String, dynamic> toJson({required String appKey, required String submittedAt}) {
final meta = Map<String, String>.from(metadata);
meta['sdk'] = 'cupthread-flutter';
meta['platform'] = platform.wireValue;
meta['submittedAt'] = submittedAt;
return {
'appKey': appKey,
'title': title.trim(),
'description': description.trim(),
if (reporterName != null && reporterName!.trim().isNotEmpty)
'reporterName': reporterName!.trim(),
if (reporterEmail != null && reporterEmail!.trim().isNotEmpty)
'reporterEmail': reporterEmail!.trim(),
'platform': platform.wireValue,
if (appVersion != null && appVersion!.trim().isNotEmpty)
'appVersion': appVersion!.trim(),
if (buildNumber != null && buildNumber!.trim().isNotEmpty)
'buildNumber': buildNumber!.trim(),
'metadata': meta,
'attachments': attachments.map((a) => a.toJson()).toList(),
};
}