import { Module, forwardRef } from '@nestjs/common';
import { AuthService } from './services/auth.service';
import { AuthController } from './controllers/auth.controller';
import { UtilsModule } from '../utils/utils.module';
import { UserModule } from '../users/user.module';
import { JwtModule } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { AdminModule } from '../admin/admin.module';
import { TokensService } from './services/tokens.service';
import { RestaurantsModule } from '../restaurants/restaurants.module';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { User } from '../users/entities/user.entity';
import { AdminAuthGuard } from './guards/adminAuth.guard';
import { RefreshToken } from './entities/refresh-token.entity';
import { NotificationsModule } from '../notifications/notifications.module';

@Module({
  imports: [
    UtilsModule,
    forwardRef(() => UserModule),
    JwtModule.registerAsync({
      useFactory: (configService: ConfigService) => {
        const expiresIn = configService.getOrThrow<number>('JWT_EXPIRATION_TIME');
        return {
          global: true,
          secret: configService.getOrThrow<string>('JWT_SECRET'),
          signOptions: {
            // Use string format with time unit for explicit expiration (value should be in seconds)
            expiresIn: `${expiresIn}s`,
          },
        };
      },
      inject: [ConfigService],
    }),
    forwardRef(() => AdminModule),
    forwardRef(() => RestaurantsModule),
    MikroOrmModule.forFeature([User, RefreshToken]),
    forwardRef(() => NotificationsModule),
    
  ],
  controllers: [AuthController],
  providers: [AuthService, TokensService, AdminAuthGuard],
  exports: [AdminAuthGuard],
})
export class AuthModule {}
