import { SharedModule } from '@aurora/shared.module';
import { Module } from '@nestjs/common';
import { AuthController } from './controllers/auth.controller';
import { PkceVerifierStoreService } from './pkce/pkce-verifier-store.service';

@Module({
  imports: [SharedModule],
  controllers: [AuthController],
  providers: [
    // Manually maintained — server-side PKCE verifier store.
    // Stores the code_verifier keyed by state for the Authorization Code flow.
    // Design: in-memory Map + 5-min TTL + single-use take.
    // Swap for a Redis-backed impl (same interface) when multi-replica BFF is needed.
    //
    // useFactory (not a bare class provider): the constructor takes a primitive `ttlMs`
    // param. Nest resolves deps by `design:paramtypes` and does NOT honor TS default
    // values, so `providers: [PkceVerifierStoreService]` would make it try to resolve a
    // `Number` provider and throw UnknownDependenciesException at boot. The factory
    // constructs it explicitly with the default TTL; unit tests still `new` it with a
    // short TTL directly.
    {
      provide: PkceVerifierStoreService,
      useFactory: (): PkceVerifierStoreService => new PkceVerifierStoreService(),
    },
  ],
})
export class AuthorizationCodeModule {}
