import { Module } from '@nestjs/common';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { AuthModule } from './auth.module';
import { ModuleLinkerService } from './services/module-linker.service';
import { NotificationService } from './services/notification.service';
import { NotificationRuleService } from './services/notification-rule.service';
import { ModuleRegistryService } from './services/module-registry.service';
import { AuthController } from './api/auth.controller';
import { NotificationRuleSchema } from './entities/notification-rule.entity';

@Module({
  imports: [
    EventEmitterModule.forRoot(),
    MikroOrmModule.forRoot({
      driver: (require('@mikro-orm/postgresql').PostgreSqlDriver) as any,
      host: process.env.DB_HOST || 'localhost',
      port: Number(process.env.DB_PORT) || 5432,
      user: process.env.DB_USER || 'postgres',
      password: process.env.DB_PASSWORD || 'postgres',
      dbName: process.env.DB_NAME || 'planner',
      autoLoadEntities: false,
      migrations: {
        path: 'dist/migrations',
        transactional: true,
        emit: 'js',
      },
    }),
    AuthModule,
    MikroOrmModule.forFeature([NotificationRuleSchema]),
  ],
  providers: [
    ModuleLinkerService,
    NotificationService,
    NotificationRuleService,
    ModuleRegistryService,
  ],
  controllers: [AuthController],
  exports: [
    EventEmitterModule,
    AuthModule,
    ModuleLinkerService,
    NotificationService,
    NotificationRuleService,
    ModuleRegistryService,
  ],
})
export class CoreModule {}
