import { Injectable } from '@nestjs/common';
import { createAnonymousAccount } from '../../../domain/anonymous-account';
import type { AuthenticatedAccount, IAccountLoader } from '../../../domain/ports';

/**
 * Framework-default implementation of `IAccountLoader` for scaffolds that have no IAM
 * bounded context (e.g. `OAUTH_STRATEGY=none`, no-IAM install).
 *
 * Provided directly inside the published scaffold's `AuthenticationModule` (inserted by the
 * packager step in `scripts/packager/backend/application.mjs`) so the module is self-sufficient
 * without a cross-BC bridge. The catalyst SOURCE `authentication.module.ts` does NOT register
 * this provider — the two placements never coexist.
 *
 * When a real IAM bridge IS present (full install), the module-scoped anonymous default would
 * shadow the @Global() BridgesModule's ACCOUNT_LOADER export — NestJS resolves module-scoped
 * providers BEFORE falling back to @Global ones (module-wins). That is precisely why this
 * adapter is scaffold-only: in a full install the IAM bridge is the sole provider.
 *
 * Behaviour: returns `createAnonymousAccount()` regardless of the requested `accountId`.
 * In none-mode this method is never called (`AuthenticationJwtGuard` short-circuits passport),
 * so the return value is a safe-but-unused placeholder.
 */
@Injectable()
export class AnonymousAccountLoaderAdapter implements IAccountLoader {
  loadById(_accountId: string): Promise<AuthenticatedAccount | null> {
    return Promise.resolve(createAnonymousAccount());
  }
}
