import type { LambdaDefinition, MicroserviceDefinition } from '../../../lib/runtime-web/types';
/**
 * Error thrown when initialization function execution fails.
 *
 * Provides detailed context about the failure including Lambda ID,
 * service name, initialization phase, and the original error.
 *
 * @example
 * ```typescript
 * try {
 *   await initManager.executeInit(lambdaId, lambdaDef, microDef, ties);
 * } catch (error) {
 *   if (error instanceof InitializationError) {
 *     console.error(`Init failed for ${error.lambdaId} during ${error.phase}`);
 *     console.error(`Original error: ${error.originalError.message}`);
 *   }
 * }
 * ```
 */
export declare class InitializationError extends Error {
    readonly lambdaId: string;
    readonly serviceName: string;
    readonly phase: 'microservice' | 'lambda';
    readonly originalError: Error;
    /**
     * Create a new initialization error.
     *
     * @param lambdaId - Full Lambda ID (e.g., 'payments.charge')
     * @param serviceName - Name of the microservice
     * @param phase - Initialization phase ('microservice' or 'lambda')
     * @param originalError - The original error that caused the failure
     */
    constructor(lambdaId: string, serviceName: string, phase: 'microservice' | 'lambda', originalError: Error);
}
/**
 * Manages initialization function execution and snapshot caching.
 *
 * The InitManager is responsible for:
 * - Executing microservice-level init functions
 * - Executing lambda-level init functions
 * - Merging snapshots with proper precedence (lambda overrides microservice)
 * - Caching snapshots for warm invocations
 * - Error handling and logging
 *
 * ## Execution Order
 *
 * When both microservice-level and lambda-level init functions exist:
 * 1. Microservice init executes first
 * 2. Lambda init executes second (only if microservice init succeeds)
 * 3. Snapshots are merged with lambda-level taking precedence
 *
 * ## Caching Behavior
 *
 * - Init functions execute exactly once per Lambda execution environment (cold start)
 * - Snapshots are cached by Lambda ID
 * - Warm invocations retrieve cached snapshots without re-executing init
 *
 * @example
 * ```typescript
 * const initManager = new InitManager();
 *
 * // Execute init during cold start
 * const snapshot = await initManager.executeInit(
 *   'payments.charge',
 *   lambdaDefinition,
 *   microserviceDefinition,
 *   resolvedTies
 * );
 *
 * // Check if init has been executed
 * if (initManager.hasExecutedInit('payments.charge')) {
 *   const cached = initManager.getCachedSnapshot('payments.charge');
 * }
 * ```
 */
export declare class InitManager {
    private readonly logger;
    /**
     * Cache for storing snapshots by Lambda ID.
     * Key: Full Lambda ID (e.g., 'payments.charge')
     * Value: Merged snapshot from init functions
     */
    private readonly snapshotCache;
    /**
     * Set of Lambda IDs that have had their init functions executed.
     * Used to track cold start vs warm invocation.
     */
    private readonly initExecuted;
    /**
     * Create a new InitManager instance.
     *
     * Initializes the logger, snapshot cache, and init execution tracker.
     */
    constructor();
    /**
     * Execute init functions and return combined snapshot.
     *
     * Executes microservice-level init first (if defined), then lambda-level init
     * (if defined). Merges snapshots with lambda-level taking precedence.
     * Caches the result for warm invocations.
     *
     * ## Execution Flow
     *
     * 1. Check if init has already been executed (warm invocation)
     * 2. Execute microservice init (if defined)
     * 3. Execute lambda init (if defined)
     * 4. Merge snapshots (lambda overrides microservice)
     * 5. Cache result and mark as executed
     *
     * ## Error Handling
     *
     * - If microservice init fails, lambda init is NOT executed
     * - If lambda init fails, the error is propagated
     * - All errors are wrapped in InitializationError with full context
     *
     * @template TTies - Type of the ties object
     * @template TLambdaSnapshot - Type of the lambda-level snapshot
     * @template TMicroSnapshot - Type of the microservice-level snapshot
     *
     * @param lambdaId - Full Lambda ID for caching (e.g., 'payments.charge')
     * @param lambdaDef - Lambda definition with optional init function
     * @param microserviceDef - Microservice definition with optional init function
     * @param ties - Resolved ties instances from DI container
     * @returns Combined snapshot from both init functions
     * @throws InitializationError if any init function fails
     *
     * @example
     * ```typescript
     * const snapshot = await initManager.executeInit(
     *   'payments.charge',
     *   {
     *     id: 'charge',
     *     ties: { paymentService: PaymentService },
     *     init: async (ties) => ({ stripeClient: await ties.paymentService.getClient() }),
     *     handler: async (event) => { ... }
     *   },
     *   {
     *     ties: [PaymentsTies],
     *     init: async (ties) => ({ config: await ties.configService.load() }),
     *     lambdas: [...]
     *   },
     *   resolvedTies
     * );
     * // snapshot = { config: ..., stripeClient: ... }
     * ```
     */
    executeInit<TTies, TLambdaSnapshot, TMicroSnapshot>(lambdaId: string, lambdaDef: LambdaDefinition<TTies, TLambdaSnapshot>, microserviceDef: MicroserviceDefinition<TMicroSnapshot> | undefined, ties: TTies): Promise<TMicroSnapshot & TLambdaSnapshot>;
    /**
     * Get cached snapshot for warm invocations.
     *
     * Returns the cached snapshot for the specified Lambda ID, or undefined
     * if no snapshot has been cached (init not yet executed).
     *
     * @param lambdaId - Full Lambda ID (e.g., 'payments.charge')
     * @returns Cached snapshot or undefined if not cached
     *
     * @example
     * ```typescript
     * const snapshot = initManager.getCachedSnapshot('payments.charge');
     * if (snapshot) {
     *   // Use cached snapshot
     * } else {
     *   // Need to execute init first
     * }
     * ```
     */
    getCachedSnapshot(lambdaId: string): unknown | undefined;
    /**
     * Check if init has been executed for a Lambda.
     *
     * Returns true if the init functions have been executed for the specified
     * Lambda ID (cold start has occurred), false otherwise.
     *
     * @param lambdaId - Full Lambda ID (e.g., 'payments.charge')
     * @returns True if init has been executed, false otherwise
     *
     * @example
     * ```typescript
     * if (initManager.hasExecutedInit('payments.charge')) {
     *   // Warm invocation - use cached snapshot
     * } else {
     *   // Cold start - need to execute init
     * }
     * ```
     */
    hasExecutedInit(lambdaId: string): boolean;
    /**
     * Clear cached snapshot for a Lambda (for testing).
     *
     * Removes the cached snapshot and execution marker for the specified
     * Lambda ID. This is primarily useful for testing scenarios where
     * you need to simulate multiple cold starts.
     *
     * @param lambdaId - Full Lambda ID to clear
     *
     * @example
     * ```typescript
     * // In tests
     * initManager.clearCache('payments.charge');
     * // Next executeInit will run init functions again
     * ```
     */
    clearCache(lambdaId: string): void;
    /**
     * Clear all cached snapshots (for testing).
     *
     * Removes all cached snapshots and execution markers. This is primarily
     * useful for testing scenarios where you need to reset the entire state.
     *
     * @example
     * ```typescript
     * // In tests
     * initManager.clearAllCaches();
     * // All Lambdas will execute init on next invocation
     * ```
     */
    clearAllCaches(): void;
}
