import {Module} from '@nestjs/common';
import {LdapModule} from './ldap/ldap.module';
import {UserModule} from './user/user.module';
import {TypeOrmModule} from "@nestjs/typeorm";
import {ConfigModule, ConfigService} from "@nestjs/config";
import {SnakeNamingStrategy} from 'typeorm-naming-strategies';


const DataModule = TypeOrmModule.forRootAsync({
    imports: [ConfigModule],
    useFactory: (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('DB_HOST'),
        port: +configService.get('DB_PORT'),
        username: configService.get('DB_USER'),
        password: configService.get('DB_PASSWD'),
        database: configService.get('DB_NAME'),
        connectTimeout: 20000,
        entities: [],
        synchronize: false,
        autoLoadEntities: true,
        namingStrategy: new SnakeNamingStrategy(),
    }),
    inject: [ConfigService],
});

@Module({
    imports: [ConfigModule.forRoot(), DataModule, LdapModule, UserModule],
    controllers: [],
    providers: [],
})
export class AppModule {
}
