import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { StripeModule } from './stripe';
import { PlansModule } from './plans';
import { AdminModule } from './admin';
import { AuthModule } from './auth';
import { FcmTokensModule } from './fcm-tokens/fcm-tokens.module';
import { ExternalServicesModule } from './external-services/external-services.module';
import { EmailModule } from './email/email.module';
import { CredentialsModule } from './credentials/credentials.module';

import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true, envFilePath: '.env' }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        type: 'postgres',
        url: configService.get('DATABASE_URL'),
        autoLoadEntities: true,
        synchronize: false, // Managed by Go migrations
      }),
      inject: [ConfigService],
    }),
    AuthModule,
    StripeModule,
    PlansModule,
    AdminModule,
    FcmTokensModule,
    ExternalServicesModule,
    EmailModule, // Register Email Module
    CredentialsModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule { }

