Map<String, Object?> toJson() => { if (role case final role?) 'role': role, 'parts': parts.map((p) => p.toJson()).toList() };