import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { CommonModule } from './common/common.module';
import { SharedModule } from './shared/shared.module';
import { JwtModule } from './common/jwt/jwt.module';
import { JwtStrategy } from './common/jwt/jwt.strategy';
import { FarmModule } from './farm/farm.module';
import { CowModule } from './cow/cow.module';
import { GenomeModule } from './genome/genome.module';
import { MptModule } from './mpt/mpt.module';
import { GeneModule } from './gene/gene.module';
import { SystemModule } from './system/system.module';
import { AdminModule } from './admin/admin.module';
import { ExcelModule } from './common/excel/excel.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        type: 'postgres',
        host: configService.get('POSTGRES_HOST'),
        port: configService.get('POSTGRES_PORT'),
        username: configService.get('POSTGRES_USER'),
        password: configService.get('POSTGRES_PASSWORD'),
        database: configService.get('POSTGRES_DB'),
        synchronize: configService.get('POSTGRES_SYNCHRONIZE'),
        logging: configService.get('POSTGRES_LOGGING'),
        autoLoadEntities: true,
        entities: [],
      }),
    }),
    // 인프라 모듈
    JwtModule,
    CommonModule,
    SharedModule,
    
    // 인증/사용자 모듈
    AuthModule,
    UserModule,
    
    // 비즈니스 모듈
    FarmModule,
    CowModule,
    GenomeModule,
    GeneModule,
    MptModule,

    // 관리자 모듈
    AdminModule,

    // 기타
    SystemModule,
    ExcelModule,
  ],
  controllers: [AppController],
  providers: [AppService, JwtStrategy],
})
export class AppModule {}
