buildTopicRowsForUpload function
Build flat topic row maps for Supabase insertion (depth-first).
Implementation
@visibleForTesting
void buildTopicRowsForUpload({
required List<dynamic> topics,
required String domainId,
required String? parentId,
required List<Map<String, dynamic>> rows,
required Map<String, String> titleToId,
required Uuid uuid,
}) {
for (final t in topics) {
if (t is! Map<String, dynamic>) continue;
final id = uuid.v4();
final title = t['title'] as String? ?? '';
titleToId[title] = id;
rows.add({
'id': id,
'domain_id': domainId,
'parent_topic_id': parentId,
'book_id': null,
'title': title,
'depth': t['depth'] ?? 0,
'sort_order': t['sort_order'] ?? 0,
});
final children = t['children'];
if (children is List && children.isNotEmpty) {
buildTopicRowsForUpload(
topics: children,
domainId: domainId,
parentId: id,
rows: rows,
titleToId: titleToId,
uuid: uuid,
);
}
}
}