import { Global, Module } from '@nestjs/common';
import { PersonAndUserProvisioner } from './person-and-user-provisioner.service';
import { UserDirectoryService } from './user-directory.service';

/**
 * `UsersModule` — owns the portal-side identity surface.
 *
 * v1 ships two services:
 *   - `UserDirectoryService` (ADR-0020 §"User list") — the persistent
 *     sign-in cache. Upserts a `UserDirectoryEntry` per sign-in;
 *     read by the `/api/admin/users` admin endpoint. Best-effort.
 *   - `PersonAndUserProvisioner` (ADR-0026 §"Lifecycle") — lazy-creates
 *     the `Person` + `User` pair at first sign-in and returns the
 *     UUIDs the `PrincipalBuilder` needs. Blocking.
 *
 * Both run from `SessionEstablisher.establish` with different
 * invariants (best-effort vs blocking). A future PR may fold the
 * UserDirectoryEntry cache into Person+User now that the latter
 * exists — out of scope here.
 *
 * Declared `@Global()` so `SessionEstablisher` (auth module) can
 * inject both providers without re-routing the module graph.
 */
@Global()
@Module({
  providers: [UserDirectoryService, PersonAndUserProvisioner],
  exports: [UserDirectoryService, PersonAndUserProvisioner],
})
export class UsersModule {}
