import * as dotenv from 'dotenv';

const envFilePath =
  process.env.NODE_ENV == 'production'
    ? '.env'
    : `.env.${process.env.NODE_ENV || 'development'}`;
dotenv.config({ path: envFilePath });

import { NestFactory } from '@nestjs/core';
import { AppModule } from '../app.module';
import { CampaignService } from '../modules/campaign/campaign.services';

/**
 * One-off seeder: sync CometChat group tags/name/icon/description
 * for all campaign influencers whose campaign status is running.
 *
 * Run: npm run seed:running-campaign-cometchat
 * (build first: npm run build)
 */
async function bootstrap() {
  const app = await NestFactory.createApplicationContext(AppModule, {
    logger: ['error', 'warn', 'log'],
  });

  try {
    const campaignService = app.get(CampaignService);
    console.log('Starting CometChat sync for running campaign influencers...');
    const result = await campaignService.updateRunningCampaignInfluencerCometChatGroups();
    console.log('CometChat sync completed:', result);
  } catch (error) {
    console.error('CometChat sync seeder failed:', error);
    process.exitCode = 1;
  } finally {
    await app.close();
  }
}

bootstrap();
