import { typeORMConfig } from '@/config/typeorm';
import { Keyv } from '@keyv/redis';
import { CacheModule } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { JwtModule } from '@nestjs/jwt';
import { ThrottlerModule } from '@nestjs/throttler';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { CacheableMemory } from 'cacheable';
import { createKeyv } from '@keyv/redis';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    ThrottlerModule.forRoot({
      throttlers: [
        {
          limit: 20,
          ttl: 60 * 1000,
        },
      ],
    }),
    JwtModule.register({
      global: true,
      secret: process.env.SECRET_KEY,
      signOptions: { expiresIn: '15m' },
    }),
    EventEmitterModule.forRoot({ wildcard: true, global: true }),
    TypeOrmModule.forRoot({
      ...(typeORMConfig as TypeOrmModuleOptions),
    }),
    // CacheModule.registerAsync({
    //   isGlobal: true,
    //   useFactory: async (configService: ConfigService) => ({
    //     // ttl: configService.get('CACHE_TTL'),
    //     stores: [
    //       new Keyv({
    //         store: new CacheableMemory({ ttl: 60000, lruSize: 5000 }),
    //       }),
    //       createKeyv(
    //         `redis://${configService.get('REDIS_HOST')}:${configService.get('REDIS_PORT')}`,
    //       ),
    //     ],
    //   }),
    //   inject: [ConfigService],
    // }),
  ],
})
export class AppConfigsModule {}
