Map<String, Object?> toJson() => { 'type': type, 'fields': [for (var field in fields) field.toJson()], if (gates) 'gates': true, };