import { prisma } from "@/module/_global";
import {
   seederAdmin,
   seederAdminRole,
   seederDesa,
   seederGroup,
   seederPosition,
   seederTheme,
   seederUser,
   seederUserRole
} from '@/module/seeder';

async function seedCompleteVillageData() {
   console.log("Starting complete village data seeding process...");

   // Define comprehensive dummy data variables outside transaction scope
   // GROUP - Comprehensive dummy data
   const seederGroupComprehensive = [
      {
         "id": "group_rt01",
         "idVillage": "desaDummy",
         "name": "Dinas"
      },
      {
         "id": "group_rt02",
         "idVillage": "desaDummy",
         "name": "Adat"
      },
      {
         "id": "group_karang_taruna",
         "idVillage": "desaDummy",
         "name": "Karang Taruna"
      },
      {
         "id": "group_bumdes",
         "idVillage": "desaDummy",
         "name": "PKK"
      }
   ];

   // POSITION - Comprehensive dummy data
   const seederPositionComprehensive = [
      {
         "id": "pos_ketua_rt01",
         "idGroup": "group_rt01",
         "name": "Perbekel"
      },
      {
         "id": "pos_sekretaris_rt01",
         "idGroup": "group_rt01",
         "name": "Sekretaris"
      },
      {
         "id": "pos_bendahara_rt01",
         "idGroup": "group_rt01",
         "name": "Bendahara"
      },
      {
         "id": "pos_staff_rt01",
         "idGroup": "group_rt01",
         "name": "Staff"
      },
      {
         "id": "pos_staff_rt02",
         "idGroup": "group_rt02",
         "name": "Staff"
      },
      {
         "id": "pos_ketua_karang_taruna",
         "idGroup": "group_karang_taruna",
         "name": "Ketua Karang Taruna"
      },
      {
         "id": "pos_ketua_bumdes",
         "idGroup": "group_bumdes",
         "name": "Ketua PKK"
      }
   ];

   // USER - Comprehensive dummy data
   const seederUserComprehensive = [
      {
         "id": "user_kades",
         "idUserRole": "supadmin",
         "idVillage": "desaDummy",
         "idGroup": "group_rt01",
         "idPosition": "pos_ketua_rt01",
         "nik": "3201010101010001",
         "name": "Kepala Desa",
         "phone": "081234567890",
         "email": "kades@desamandiri.test",
         "gender": "M"
      },
      {
         "id": "user_sekdes",
         "idUserRole": "admin",
         "idVillage": "desaDummy",
         "idGroup": "group_rt01",
         "idPosition": "pos_sekretaris_rt01",
         "nik": "3201010101010002",
         "name": "Sekretaris Desa",
         "phone": "081234567891",
         "email": "sekdes@desamandiri.test",
         "gender": "M"
      },
      {
         "id": "user_ketua_bumdes",
         "idUserRole": "admin",
         "idVillage": "desaDummy",
         "idGroup": "group_bumdes",
         "idPosition": "pos_ketua_bumdes",
         "nik": "3201010101010003",
         "name": "Ketua BUMDES",
         "phone": "081234567892",
         "email": "ketuabumdes@desamandiri.test",
         "gender": "M"
      },
      {
         "id": "user_ketua_karang_taruna",
         "idUserRole": "user",
         "idVillage": "desaDummy",
         "idGroup": "group_karang_taruna",
         "idPosition": "pos_ketua_karang_taruna",
         "nik": "3201010101010004",
         "name": "Ketua Karang Taruna",
         "phone": "081234567893",
         "email": "ketuakt@desamandiri.test",
         "gender": "M"
      },
      {
         "id": "user_warga1",
         "idUserRole": "user",
         "idVillage": "desaDummy",
         "idGroup": "group_rt01",
         "idPosition": "pos_staff_rt01",
         "nik": "3201010101010005",
         "name": "Warga Satu",
         "phone": "081234567894",
         "email": "wargasatu@desamandiri.test",
         "gender": "F"
      },
      {
         "id": "user_warga2",
         "idUserRole": "user",
         "idVillage": "desaDummy",
         "idGroup": "group_rt02",
         "idPosition": "pos_staff_rt02",
         "nik": "3201010101010006",
         "name": "Warga Dua",
         "phone": "081234567895",
         "email": "wargadua@desamandiri.test",
         "gender": "M"
      }
   ];

   // ANNOUNCEMENTS - Comprehensive dummy data
   const seederAnnouncementComprehensive = [
      {
         "id": "ann_pembangunan_jalan",
         "idVillage": "desaDummy",
         "title": "Pembangunan Jalan Desa Tahap 2",
         "desc": "Pada bulan ini akan dilakukan pembangunan jalan desa tahap 2 yang mencakup wilayah RT 01 dan RT 02. Mohon kerjasama warga untuk menyesuaikan aktivitas selama masa pembangunan.",
         "createdBy": "user_kades"
      },
      {
         "id": "ann_posyandu",
         "idVillage": "desaDummy",
         "title": "Posyandu Bulanan",
         "desc": "Posyandu bulan akan diselenggarakan pada tanggal 21 setiap bulannya di Balai Desa. Warga diharapkan aktif membawa balita untuk pemeriksaan kesehatan.",
         "createdBy": "user_sekdes"
      },
      {
         "id": "ann_rapat_warga",
         "idVillage": "desaDummy",
         "title": "Rapat Warga Bulanan",
         "desc": "Rapat warga bulanan akan diselenggarakan pada hari Sabtu, 25 Februari 2026 pukul 09.00 WIB di Balai Desa. Hadirilah tepat waktu.",
         "createdBy": "user_kades"
      }
   ];

   // ANNOUNCEMENT MEMBERS - Comprehensive dummy data
   const seederAnnouncementMemberComprehensive = [
      {
         "id": "ann_mem_pembangunan_jalan_rt01",
         "idAnnouncement": "ann_pembangunan_jalan",
         "idGroup": "group_rt01",
         "idDivision": null
      },
      {
         "id": "ann_mem_pembangunan_jalan_rt02",
         "idAnnouncement": "ann_pembangunan_jalan",
         "idGroup": "group_rt02",
         "idDivision": null
      },
      {
         "id": "ann_mem_posyandu_all",
         "idAnnouncement": "ann_posyandu",
         "idGroup": null,
         "idDivision": null
      },
      {
         "id": "ann_mem_rapat_warga_all",
         "idAnnouncement": "ann_rapat_warga",
         "idGroup": null,
         "idDivision": null
      }
   ];

   // DIVISIONS - Comprehensive dummy data
   const seederDivisionComprehensive = [
      {
         "id": "div_bumdes",
         "idVillage": "desaDummy",
         "idGroup": "group_bumdes",
         "name": "BUMDES Desa Mandiri",
         "desc": "Badan Usaha Milik Desa yang bertujuan untuk meningkatkan kesejahteraan masyarakat desa melalui berbagai usaha produktif.",
         "createdBy": "user_ketua_bumdes"
      },
      {
         "id": "div_karang_taruna",
         "idVillage": "desaDummy",
         "idGroup": "group_karang_taruna",
         "name": "Karang Taruna Desa Mandiri",
         "desc": "Organisasi pemuda desa yang berfokus pada pengembangan potensi pemuda dan kegiatan sosial kemasyarakatan.",
         "createdBy": "user_ketua_karang_taruna"
      },
      {
         "id": "div_linmas",
         "idVillage": "desaDummy",
         "idGroup": "group_rt01",
         "name": "Linmas Desa Mandiri",
         "desc": "Perlindungan Masyarakat yang bertugas menjaga ketertiban dan keamanan di wilayah desa.",
         "createdBy": "user_kades"
      }
   ];

   // DIVISION MEMBERS - Comprehensive dummy data
   const seederDivisionMemberComprehensive = [
      {
         "id": "div_mem_bumdes_ketua",
         "idDivision": "div_bumdes",
         "idUser": "user_ketua_bumdes",
         "isAdmin": true,
         "isLeader": true
      },
      {
         "id": "div_mem_bumdes_anggota1",
         "idDivision": "div_bumdes",
         "idUser": "user_warga1",
         "isAdmin": false,
         "isLeader": false
      },
      {
         "id": "div_mem_karang_taruna_ketua",
         "idDivision": "div_karang_taruna",
         "idUser": "user_ketua_karang_taruna",
         "isAdmin": true,
         "isLeader": true
      },
      {
         "id": "div_mem_karang_taruna_anggota1",
         "idDivision": "div_karang_taruna",
         "idUser": "user_warga2",
         "isAdmin": false,
         "isLeader": false
      },
      {
         "id": "div_mem_linmas_kades",
         "idDivision": "div_linmas",
         "idUser": "user_kades",
         "isAdmin": true,
         "isLeader": true
      }
   ];

   // PROJECTS - Comprehensive dummy data
   const seederProjectComprehensive = [
      {
         "id": "proj_pembangunan_jalan",
         "idVillage": "desaDummy",
         "idGroup": "group_rt01",
         "title": "Pembangunan Jalan Desa Tahap 2",
         "desc": "Pembangunan jalan desa tahap 2 yang mencakup wilayah RT 01 dan RT 02",
         "status": 1,
         "createdBy": "user_kades"
      },
      {
         "id": "proj_penghijauan",
         "idVillage": "desaDummy",
         "idGroup": "group_karang_taruna",
         "title": "Program Penghijauan Desa",
         "desc": "Penanaman pohon di sepanjang jalan desa dan area publik",
         "status": 0,
         "createdBy": "user_ketua_karang_taruna"
      },
      {
         "id": "proj_pembukuan_bumdes",
         "idVillage": "desaDummy",
         "idGroup": "group_bumdes",
         "title": "Sistem Pembukuan Digital BUMDES",
         "desc": "Pembuatan sistem pembukuan digital untuk BUMDES Desa Mandiri",
         "status": 0,
         "createdBy": "user_ketua_bumdes"
      }
   ];

   // PROJECT MEMBERS - Comprehensive dummy data
   const seederProjectMemberComprehensive = [
      {
         "id": "proj_mem_pembangunan_jalan_kades",
         "idProject": "proj_pembangunan_jalan",
         "idUser": "user_kades",
         "isLeader": true
      },
      {
         "id": "proj_mem_pembangunan_jalan_sekdes",
         "idProject": "proj_pembangunan_jalan",
         "idUser": "user_sekdes",
         "isLeader": false
      },
      {
         "id": "proj_mem_penghijauan_ketua_kt",
         "idProject": "proj_penghijauan",
         "idUser": "user_ketua_karang_taruna",
         "isLeader": true
      },
      {
         "id": "proj_mem_penghijauan_warga1",
         "idProject": "proj_penghijauan",
         "idUser": "user_warga1",
         "isLeader": false
      },
      {
         "id": "proj_mem_pembukuan_bumdes_ketua",
         "idProject": "proj_pembukuan_bumdes",
         "idUser": "user_ketua_bumdes",
         "isLeader": true
      }
   ];

   // PROJECT TASKS - Comprehensive dummy data
   const seederProjectTaskComprehensive = [
      {
         "id": "task_survey_lokasi",
         "idProject": "proj_pembangunan_jalan",
         "title": "Survey Lokasi",
         "desc": "Melakukan survey lokasi untuk menentukan titik pembangunan jalan",
         "status": 1,
         "dateStart": "2026-01-15T00:00:00.000Z",
         "dateEnd": "2026-01-20T00:00:00.000Z"
      },
      {
         "id": "task_pengadaan_material",
         "idProject": "proj_pembangunan_jalan",
         "title": "Pengadaan Material",
         "desc": "Mengadakan material pembangunan seperti pasir, batu, dan semen",
         "status": 0,
         "dateStart": "2026-02-01T00:00:00.000Z",
         "dateEnd": "2026-02-10T00:00:00.000Z"
      },
      {
         "id": "task_pelaksanaan_pembangunan",
         "idProject": "proj_pembangunan_jalan",
         "title": "Pelaksanaan Pembangunan",
         "desc": "Melaksanakan pembangunan jalan sesuai dengan desain yang telah ditentukan",
         "status": 0,
         "dateStart": "2026-02-15T00:00:00.000Z",
         "dateEnd": "2026-03-15T00:00:00.000Z"
      },
      {
         "id": "task_penanaman_pohon",
         "idProject": "proj_penghijauan",
         "title": "Penanaman Pohon",
         "desc": "Menanam pohon di sepanjang jalan desa dan area publik",
         "status": 0,
         "dateStart": "2026-03-01T00:00:00.000Z",
         "dateEnd": "2026-03-15T00:00:00.000Z"
      }
   ];

   // DISCUSSIONS - Comprehensive dummy data
   const seederDiscussionComprehensive = [
      {
         "id": "disc_kegiatan_desa",
         "idVillage": "desaDummy",
         "idGroup": null,
         "title": "Pembahasan Kegiatan Desa Mendatang",
         "desc": "Diskusi untuk merencanakan kegiatan desa yang akan datang dan menyerap aspirasi warga",
         "status": 1,
         "createdBy": "user_kades"
      },
      {
         "id": "disc_pengelolaan_sampah",
         "idVillage": "desaDummy",
         "idGroup": "group_rt01",
         "title": "Pengelolaan Sampah di RT 01",
         "desc": "Diskusi internal RT 01 mengenai pengelolaan sampah rumah tangga dan lingkungan",
         "status": 1,
         "createdBy": "user_kades"
      },
      {
         "id": "disc_program_karang_taruna",
         "idVillage": "desaDummy",
         "idGroup": "group_karang_taruna",
         "title": "Program Kerja Karang Taruna",
         "desc": "Merancang program kerja Karang Taruna untuk tahun ini",
         "status": 1,
         "createdBy": "user_ketua_karang_taruna"
      }
   ];

   // DISCUSSION MEMBERS - Comprehensive dummy data
   const seederDiscussionMemberComprehensive = [
      {
         "id": "disc_mem_kegiatan_desa_kades",
         "idDiscussion": "disc_kegiatan_desa",
         "idUser": "user_kades"
      },
      {
         "id": "disc_mem_kegiatan_desa_sekdes",
         "idDiscussion": "disc_kegiatan_desa",
         "idUser": "user_sekdes"
      },
      {
         "id": "disc_mem_kegiatan_desa_warga1",
         "idDiscussion": "disc_kegiatan_desa",
         "idUser": "user_warga1"
      },
      {
         "id": "disc_mem_pengelolaan_sampah_kades",
         "idDiscussion": "disc_pengelolaan_sampah",
         "idUser": "user_kades"
      },
      {
         "id": "disc_mem_pengelolaan_sampah_warga1",
         "idDiscussion": "disc_pengelolaan_sampah",
         "idUser": "user_warga1"
      },
      {
         "id": "disc_mem_program_kt_ketua",
         "idDiscussion": "disc_program_karang_taruna",
         "idUser": "user_ketua_karang_taruna"
      },
      {
         "id": "disc_mem_program_kt_warga2",
         "idDiscussion": "disc_program_karang_taruna",
         "idUser": "user_warga2"
      }
   ];

   try {
      // Start transaction to ensure data consistency
      await prisma.$transaction(async (tx) => {

         // ADMIN ROLE
         for (let data of seederAdminRole) {
            await tx.adminRole.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name
               },
               create: {
                  id: data.id,
                  name: data.name,
               },
            })
         }

         // ADMIN
         for (let data of seederAdmin) {
            await tx.admin.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name,
                  idAdminRole: data.idAdminRole,
                  phone: data.phone,
                  email: data.email,
                  gender: data.gender
               },
               create: {
                  id: data.id,
                  idAdminRole: data.idAdminRole,
                  phone: data.phone,
                  email: data.email,
                  gender: data.gender,
                  name: data.name
               },
            })
         }

         // THEME
         for (let data of seederTheme) {
            await tx.colorTheme.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name,
                  utama: data.utama,
                  bgUtama: data.bgUtama,
                  bgIcon: data.bgIcon,
                  bgFiturHome: data.bgFiturHome,
                  bgFiturDivision: data.bgFiturDivisi,
                  bgTotalKegiatan: data.bgTotalKegiatan
               },
               create: {
                  id: data.id,
                  name: data.name,
                  utama: data.utama,
                  bgUtama: data.bgUtama,
                  bgIcon: data.bgIcon,
                  bgFiturHome: data.bgFiturHome,
                  bgFiturDivision: data.bgFiturDivisi,
                  bgTotalKegiatan: data.bgTotalKegiatan
               }
            })
         }

         // DESA - Original data
         for (let data of seederDesa) {
            await tx.village.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name,
                  desc: data.desc,
                  idTheme: "theme1"
               },
               create: {
                  id: data.id,
                  name: data.name,
                  desc: data.desc,
                  idTheme: "theme1"
               }
            })
         }

         // GROUP - Original data
         for (let data of seederGroup) {
            await tx.group.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name,
                  idVillage: data.idVillage
               },
               create: {
                  id: data.id,
                  name: data.name,
                  idVillage: data.idVillage
               }
            })
         }

         for (let data of seederGroupComprehensive) {
            await tx.group.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name,
                  idVillage: data.idVillage
               },
               create: {
                  id: data.id,
                  name: data.name,
                  idVillage: data.idVillage
               }
            })
         }

         // POSITION - Original data
         for (let data of seederPosition) {
            await tx.position.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name,
                  idGroup: data.idGroup
               },
               create: {
                  id: data.id,
                  name: data.name,
                  idGroup: data.idGroup
               }
            })
         }

         for (let data of seederPositionComprehensive) {
            await tx.position.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name,
                  idGroup: data.idGroup
               },
               create: {
                  id: data.id,
                  name: data.name,
                  idGroup: data.idGroup
               }
            })
         }

         // USER ROLE
         for (let data of seederUserRole) {
            await tx.userRole.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name
               },
               create: {
                  id: data.id,
                  name: data.name,
                  desc: data.desc
               },
            })
         }

         // USER - Original data
         for (let data of seederUser) {
            await tx.user.upsert({
               where: {
                  id: data.id
               },
               update: {
                  idVillage: data.idVillage,
                  idGroup: data.idGroup,
                  idPosition: data.idPosition,
                  idUserRole: data.idUserRole,
                  nik: data.nik,
                  name: data.name,
                  phone: data.phone,
                  email: data.email,
                  gender: data.gender
               },
               create: {
                  id: data.id,
                  idVillage: data.idVillage,
                  idGroup: data.idGroup,
                  idPosition: data.idPosition,
                  idUserRole: data.idUserRole,
                  nik: data.nik,
                  name: data.name,
                  phone: data.phone,
                  email: data.email,
                  gender: data.gender
               },
            })
         }

         for (let data of seederUserComprehensive) {
            await tx.user.upsert({
               where: {
                  id: data.id
               },
               update: {
                  idVillage: data.idVillage,
                  idGroup: data.idGroup,
                  idPosition: data.idPosition,
                  idUserRole: data.idUserRole,
                  nik: data.nik,
                  name: data.name,
                  phone: data.phone,
                  email: data.email,
                  gender: data.gender
               },
               create: {
                  id: data.id,
                  idVillage: data.idVillage,
                  idGroup: data.idGroup,
                  idPosition: data.idPosition,
                  idUserRole: data.idUserRole,
                  nik: data.nik,
                  name: data.name,
                  phone: data.phone,
                  email: data.email,
                  gender: data.gender
               },
            })
         }

         for (let data of seederAnnouncementComprehensive) {
            await tx.announcement.upsert({
               where: {
                  id: data.id
               },
               update: {
                  title: data.title,
                  desc: data.desc,
                  createdBy: data.createdBy
               },
               create: {
                  id: data.id,
                  idVillage: data.idVillage,
                  title: data.title,
                  desc: data.desc,
                  createdBy: data.createdBy,
                  isActive: true
               }
            })
         }

         for (let data of seederAnnouncementMemberComprehensive) {
            await tx.announcementMember.upsert({
               where: {
                  id: data.id
               },
               update: {
                  idAnnouncement: data.idAnnouncement,
                  idGroup: data.idGroup!,
                  idDivision: data.idDivision!
               },
               create: {
                  id: data.id,
                  idAnnouncement: data.idAnnouncement,
                  idGroup: data.idGroup!,
                  idDivision: data.idDivision!,
                  isActive: true
               }
            })
         }

         for (let data of seederDivisionComprehensive) {
            await tx.division.upsert({
               where: {
                  id: data.id
               },
               update: {
                  name: data.name,
                  desc: data.desc,
                  createdBy: data.createdBy
               },
               create: {
                  id: data.id,
                  idVillage: data.idVillage,
                  idGroup: data.idGroup,
                  name: data.name,
                  desc: data.desc,
                  createdBy: data.createdBy,
                  isActive: true
               }
            })
         }

         for (let data of seederDivisionMemberComprehensive) {
            await tx.divisionMember.upsert({
               where: {
                  id: data.id
               },
               update: {
                  idUser: data.idUser,
                  isAdmin: data.isAdmin,
                  isLeader: data.isLeader
               },
               create: {
                  id: data.id,
                  idDivision: data.idDivision,
                  idUser: data.idUser,
                  isAdmin: data.isAdmin,
                  isLeader: data.isLeader,
                  isActive: true
               }
            })
         }

         for (let data of seederProjectComprehensive) {
            await tx.project.upsert({
               where: {
                  id: data.id
               },
               update: {
                  title: data.title,
                  desc: data.desc,
                  status: data.status,
                  createdBy: data.createdBy
               },
               create: {
                  id: data.id,
                  idVillage: data.idVillage,
                  idGroup: data.idGroup,
                  title: data.title,
                  desc: data.desc,
                  status: data.status,
                  createdBy: data.createdBy,
                  isActive: true
               }
            })
         }

         for (let data of seederProjectMemberComprehensive) {
            await tx.projectMember.upsert({
               where: {
                  id: data.id
               },
               update: {
                  idUser: data.idUser,
                  isLeader: data.isLeader
               },
               create: {
                  id: data.id,
                  idProject: data.idProject,
                  idUser: data.idUser,
                  isLeader: data.isLeader,
                  isActive: true
               }
            })
         }

         for (let data of seederProjectTaskComprehensive) {
            await tx.projectTask.upsert({
               where: {
                  id: data.id
               },
               update: {
                  title: data.title,
                  desc: data.desc,
                  status: data.status,
                  dateStart: new Date(data.dateStart),
                  dateEnd: new Date(data.dateEnd)
               },
               create: {
                  id: data.id,
                  idProject: data.idProject,
                  title: data.title,
                  desc: data.desc,
                  status: data.status,
                  dateStart: new Date(data.dateStart),
                  dateEnd: new Date(data.dateEnd),
                  isActive: true
               }
            })
         }

         for (let data of seederDiscussionComprehensive) {
            await tx.discussion.upsert({
               where: {
                  id: data.id
               },
               update: {
                  title: data.title,
                  desc: data.desc,
                  status: data.status,
                  createdBy: data.createdBy
               },
               create: {
                  id: data.id,
                  idVillage: data.idVillage,
                  idGroup: data.idGroup!,
                  title: data.title,
                  desc: data.desc,
                  status: data.status,
                  createdBy: data.createdBy,
                  isActive: true
               }
            })
         }

         for (let data of seederDiscussionMemberComprehensive) {
            await tx.discussionMember.upsert({
               where: {
                  id: data.id
               },
               update: {
                  idUser: data.idUser
               },
               create: {
                  id: data.id,
                  idDiscussion: data.idDiscussion,
                  idUser: data.idUser,
                  isActive: true
               }
            })
         }
      });

      console.log("\n✅ Complete village data seeding completed successfully!");
      console.log(`📊 Total admin roles processed: ${seederAdminRole.length}`);
      console.log(`📊 Total admins processed: ${seederAdmin.length}`);
      console.log(`📊 Total themes processed: ${seederTheme.length}`);
      console.log(`📊 Total villages processed: ${seederDesa.length}`);
      console.log(`📊 Total groups processed: ${[...seederGroup, ...seederGroupComprehensive].length}`);
      console.log(`📊 Total positions processed: ${[...seederPosition, ...seederPositionComprehensive].length}`);
      console.log(`📊 Total user roles processed: ${seederUserRole.length}`);
      console.log(`📊 Total users processed: ${[...seederUser, ...seederUserComprehensive].length}`);
      console.log(`📊 Total announcements processed: ${seederAnnouncementComprehensive.length}`);
      console.log(`📊 Total announcement members processed: ${seederAnnouncementMemberComprehensive.length}`);
      console.log(`📊 Total divisions processed: ${seederDivisionComprehensive.length}`);
      console.log(`📊 Total division members processed: ${seederDivisionMemberComprehensive.length}`);
      console.log(`📊 Total projects processed: ${seederProjectComprehensive.length}`);
      console.log(`📊 Total project members processed: ${seederProjectMemberComprehensive.length}`);
      console.log(`📊 Total project tasks processed: ${seederProjectTaskComprehensive.length}`);
      console.log(`📊 Total discussions processed: ${seederDiscussionComprehensive.length}`);
      console.log(`📊 Total discussion members processed: ${seederDiscussionMemberComprehensive.length}`);
   } catch (error) {
      console.error("\n❌ Error during seeding:", error);
      throw new Error("Seeding process failed");
   } finally {
      await prisma.$disconnect();
   }
}

// Execute seeding if called directly from command line
if (require.main === module) {
   seedCompleteVillageData()
      .catch((e) => {
         console.error(e);
         process.exit(1);
      });
}

export default seedCompleteVillageData;