creating a bundle from courses

langugae :dart
framework:flutter
backend:firebase
i have a bundle which is basically multiple courses sold at a discounted price the problem is that i can’t create purchased_course documents using multiple courses ref list in bundles and each course also has its own books and videos subcollection i would love to hear your ideas for this

                  FFButtonWidget(
                    onPressed: () async {
                      await processRazorpayPayment(
                        context,
                        amount: int.parse((double var1) {
                          return var1.toStringAsFixed(2).replaceAll(".", "");
                        }(() {
                          if (_model.d1Value == true) {
                            return widget.bundle!.dPDays1.price;
                          } else if (_model.d2Value == true) {
                            return widget.bundle!.dPDays2.price;
                          } else if (_model.d3Value == true) {
                            return widget.bundle!.dPDays3.price;
                          } else if (_model.m1Value == true) {
                            return widget.bundle!.dPMonths1.price;
                          } else if (_model.m2Value == true) {
                            return widget.bundle!.dPMonths2.price;
                          } else if (_model.m3Value == true) {
                            return widget.bundle!.dPMonths3.price;
                          } else if (_model.y1Value == true) {
                            return widget.bundle!.dPYears1.price;
                          } else if (_model.y2Value == true) {
                            return widget.bundle!.dPYears2.price;
                          } else if (_model.y3Value == true) {
                            return widget.bundle!.dPYears3.price;
                          } else {
                            return null!;
                          }
                        }())),
                        currency: 'INR',
                        onReceivedResponse: (paymentId) => safeSetState(
                            () => _model.razorpayPaymentId3Copy = paymentId),
                      );

                      if (_model.razorpayPaymentId3Copy != null &&
                          _model.razorpayPaymentId3Copy != '') {
                        await currentUserReference!.update({
                          ...mapToFirestore(
                            {
                              'Pbundle': FieldValue.arrayUnion(
                                  [widget.bundle?.bundleId]),
                            },
                          ),
                        });

                        /// Handle the purchase of the bundle
                        Future<void> handleBundlePurchase(
                            DocumentReference bundleRef,
                            DocumentReference userRef) async {
                          // Fetch the bundle document
                          final bundleSnapshot = await bundleRef.get();
                          final bundleData =
                              bundleSnapshot.data() as Map<String, dynamic>;

                          // Retrieve the list of course references
                          final List<DocumentReference> courseRefs =
                              List<DocumentReference>.from(
                                  bundleData['courseref']);

                          // Iterate over each course reference
                          for (final courseRef in courseRefs) {
                            // Fetch the course document
                            final courseSnapshot = await courseRef.get();
                            final courseData =
                                courseSnapshot.data() as Map<String, dynamic>;

                            // Create a purchased course document for the user
                            final purchasedCourseRef =
                                userRef.collection('purchased_courses').doc();
                            await purchasedCourseRef.set({
                              'course_name': courseData['course_name'],
                              'purchase_date': DateTime.now(),
                              // Add more fields as needed
                            });

                            // Add books sub-collection
                            final booksSubCollection =
                                courseRef.collection('books');
                            final booksSnapshot =
                                await booksSubCollection.get();
                            for (final book in booksSnapshot.docs) {
                              await purchasedCourseRef
                                  .collection('books')
                                  .doc(book.id)
                                  .set(book.data());
                            }

                            // Add videos sub-collection
                            final videosSubCollection =
                                courseRef.collection('videos');
                            final videosSnapshot =
                                await videosSubCollection.get();
                            for (final video in videosSnapshot.docs) {
                              await purchasedCourseRef
                                  .collection('videos')
                                  .doc(video.id)
                                  .set(video.data());
                            }
                          }
                        }

i have also added bundles record field as an image and here’s purchased_course fields

  // Existing fields
  String? _name;
  String get name => _name ?? '';
  DateTime? _createdAt;
  DateTime? get createdAt => _createdAt;
  String? _astrologer;
  String get astrologer => _astrologer ?? '';
  DateTime? _expiry;
  DateTime? get expiry => _expiry;
  String? _courseID;
  String get courseID => _courseID ?? '';
  String? _description;
  String get description => _description ?? '';
  String? _coverimg;
  String get coverimg => _coverimg ?? '';
  bool? _isExpired;
  bool get isExpired => _isExpired ?? false;

  // Subcollection for books
  CollectionReference get books => reference.collection('books');
  // Subcollection for videos
  CollectionReference get videos => reference.collection('videos');
                        /// Handle the purchase of the bundle
                        Future<void> handleBundlePurchase(
                            DocumentReference bundleRef,
                            DocumentReference userRef) async {
                          // Fetch the bundle document
                          final bundleSnapshot = await bundleRef.get();
                          final bundleData =
                              bundleSnapshot.data() as Map<String, dynamic>;

                          // Retrieve the list of course references
                          final List<DocumentReference> courseRefs =
                              List<DocumentReference>.from(
                                  bundleData['courseref']);

                          // Iterate over each course reference
                          for (final courseRef in courseRefs) {
                            // Fetch the course document
                            final courseSnapshot = await courseRef.get();
                            final courseData =
                                courseSnapshot.data() as Map<String, dynamic>;

                            // Create a purchased course document for the user
                            final purchasedCourseRef =
                                userRef.collection('purchased_courses').doc();
                            await purchasedCourseRef.set({
                              'course_name': courseData['course_name'],
                              'purchase_date': DateTime.now(),
                              // Add more fields as needed
                            });

                            // Add books sub-collection
                            final booksSubCollection =
                                courseRef.collection('books');
                            final booksSnapshot =
                                await booksSubCollection.get();
                            for (final book in booksSnapshot.docs) {
                              await purchasedCourseRef
                                  .collection('books')
                                  .doc(book.id)
                                  .set(book.data());
                            }

                            // Add videos sub-collection
                            final videosSubCollection =
                                courseRef.collection('videos');
                            final videosSnapshot =
                                await videosSubCollection.get();
                            for (final video in videosSnapshot.docs) {
                              await purchasedCourseRef
                                  .collection('videos')
                                  .doc(video.id)
                                  .set(video.data());
                            }
                          }
                        }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật