import 'dotenv/config';
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ScheduleModule } from '@nestjs/schedule';
import { LeadsModule } from './leads/leads.module';
import { ConversacionModule } from './conversacion/conversacion.module';
import { WhatsappModule } from './whatsapp/whatsapp.module';
import { ClaudeModule } from './claude/claude.module';
import { MediaModule } from './media/media.module';
import { SchedulerModule } from './scheduler/scheduler.module';
import { Lead } from './leads/lead.entity';
import { Conversacion } from './conversacion/conversacion.entity';

@Module({
  imports: [
    ScheduleModule.forRoot(),
    TypeOrmModule.forRoot({
      type: 'postgres',
      url: process.env.DATABASE_URL,
      entities: [Lead, Conversacion],
      synchronize: true, // En produccion usar migrations en lugar de synchronize
      ssl: process.env.DATABASE_URL?.includes('sslmode=require')
        ? { rejectUnauthorized: false }
        : false,
    }),
    LeadsModule,
    ConversacionModule,
    WhatsappModule,
    ClaudeModule,
    MediaModule,
    SchedulerModule,
  ],
})
export class AppModule { }
