import connectToDatabase from '@/shared/config/dbConfig';
import { seedAndhraPradeshUnified } from '@/shared/seeder/location/Andhra Pradesh/seedAndhraPradeshUnified';
import { IUserDoc } from '@/modules/user/user.interfaces';
import { Types } from 'mongoose';

const runAndhraPradeshUnifiedSeedProcess = async (): Promise<void> => {
  console.info('🚀 Starting Andhra Pradesh unified seeding process...');

  try {
    await connectToDatabase();
    console.info('✅ Connected to MongoDB');

    // Find a user to use as superAdmin (typically the SuperAdmin user)
    const UserModule = await import('@/modules/user/user.model');
    const User = UserModule.default;
    const user = await User.findOne({ userType: new RegExp(`^SuperAdmin`, 'i') }) as IUserDoc | null;
    if (!user) {
      console.error('❌ SuperAdmin user not found. Please ensure SuperAdmin is created first.');
      process.exit(1);
    }

    console.info('➡️ Seeding Andhra Pradesh cities and areas...');
    await seedAndhraPradeshUnified({
      superAdminId: user._id as string | Types.ObjectId,
    });

    console.info(
      '🎉 Andhra Pradesh unified seeding completed successfully.',
    );

    process.exit(0);
  } catch (error) {
    console.error('❌ Error in Andhra Pradesh unified seeding:', error);
    process.exit(1);
  }
};

runAndhraPradeshUnifiedSeedProcess();