import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { ScheduleModule } from '@nestjs/schedule';
import { AuditModule } from './audit/audit.module';
import { OperationLogInterceptor } from './audit/operation-log.interceptor';
import { validateEnv } from './config/env';
import { packageEnvPath, rootEnvPath } from './config/paths';
import { DatabaseModule } from './database/database.module';
import { AuthModule } from './auth/auth.module';
import { AdminModule } from './admin/admin.module';
import { CatalogModule } from './catalog/catalog.module';
import { OrderLogsModule } from './order-logs/order-logs.module';
import { OrdersModule } from './orders/orders.module';
import { ThirdPartyModule } from './third-party/third-party.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      envFilePath: [rootEnvPath, packageEnvPath],
      isGlobal: true,
      validate: validateEnv,
    }),
    ScheduleModule.forRoot(),
    DatabaseModule,
    AuditModule,
    AuthModule,
    AdminModule,
    ThirdPartyModule,
    CatalogModule,
    OrdersModule,
    OrderLogsModule,
  ],
  controllers: [],
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: OperationLogInterceptor,
    },
  ],
})
export class AppModule {}
