/**
 * ContextIntentProvider — Resolves services from the context cascade.
 *
 * The fastest intent provider. Checks for pre-cached service proxies
 * that were registered at boot or cached from a previous resolution.
 * No network. No bus calls. Synchronous lookup with parent walk-up.
 *
 * This is provider #1 in the intent chain. If it misses, the chain
 * tries slower providers (bus scan, federation, semantic).
 */

import type { IIntentProvider, IActorService, ServiceContract } from './ServiceContract';

export interface IServiceLookup {
  getService<T>(key: string | symbol): T | undefined;
}

export class ContextIntentProvider implements IIntentProvider {
  constructor(private _lookup: IServiceLookup) {}

  async resolve(contract: ServiceContract): Promise<IActorService | undefined> {
    const cached = this._lookup.getService<IActorService>(contract.id);
    return cached ?? undefined;
  }
}
