
import dotenv from 'dotenv';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
dotenv.config({ path: path.join(__dirname, '../.env') });

import db from '../src/database/models/index.js';

async function run() {
  try {
    const district = await db.District.findOne({
      where: { name: { [db.Sequelize.Op.iLike]: '%South Delhi%' } }
    });

    if (!district) {
      console.log('South Delhi not found');
      return;
    }

    console.log('Current assignment for South Delhi:');
    console.log(`ddAmId: ${district.ddAmId}`);
    console.log(`asmId: ${district.asmId}`);
    console.log(`zmId: ${district.zmId}`);

    if (district.asmId) {
       console.log(`Removing ASM ${district.asmId} from South Delhi...`);
       await district.update({ asmId: null, asmCode: null });
       console.log('ASM removed.');
    }

    process.exit(0);
  } catch (error) {
    console.error('Error:', error);
    process.exit(1);
  }
}

run();
