import { PureContainer } from '@worktif/utils';
import type { LambdaDefinition, MicroserviceDefinition } from '../../../lib/runtime-web/types';
import type { RuntimeWebLambdaHandler } from './runtime-web-lambda-handler';
import { InitManager } from '../init';
/**
 * Factory for creating Lambda handlers with dependency injection.
 *
 * Transforms user-provided Lambda definitions into full Lambda handler classes
 * that extend LambdaApi and include automatic dependency injection using
 * the shared container instance. Handles hash-based dependency resolution
 * with metadata support and validates container state before handler creation.
 *
 * **Requirements**: 18.1
 *
 * @example
 * ```typescript
 * const factory = new LambdaHandlerFactory();
 * const handler = factory.create(lambdaDefinition, container);
 *
 * // Handler is ready to be invoked by AWS Lambda runtime
 * const result = await handler.handler(event, context);
 * ```
 */
export declare class LambdaHandlerFactory {
    private readonly logger;
    private readonly metadataManager;
    private readonly containerValidator;
    private dependencyMetadata;
    /**
     * Shared InitManager instance for cold start initialization.
     * Created lazily on first use and reused across all handlers.
     */
    private initManager;
    constructor();
    /**
     * Get or create the shared InitManager instance.
     *
     * Creates an InitManager lazily on first use and reuses it for all handlers.
     * This ensures consistent snapshot caching across all Lambda handlers.
     *
     * @returns The shared InitManager instance
     */
    getInitManager(): InitManager;
    /**
     * Set a custom InitManager instance.
     *
     * Allows injection of a custom InitManager for testing or advanced use cases.
     * Should be called before any handlers are created.
     *
     * @param initManager - Custom InitManager instance to use
     */
    setInitManager(initManager: InitManager): void;
    /**
     * Create a Lambda handler class instance from a definition.
     *
     * Creates a RuntimeWebLambdaHandler that extends LambdaApi and includes
     * automatic dependency injection using the shared container instance.
     * Validates container state and uses hash-based keys from metadata for
     * stable dependency resolution.
     *
     * Supports both array-based ties (legacy) and object-based ties (new pattern).
     * Emits deprecation warnings for array-based ties usage.
     *
     * ## Cold Start Initialization
     *
     * When a Lambda definition includes an `init` property, the handler will:
     * - Execute the init function during cold start (first invocation)
     * - Cache the snapshot for warm invocations
     * - Provide the snapshot via `event.snapshot` in the handler
     *
     * When a MicroserviceDefinition is provided with an `init` property:
     * - Microservice init executes first
     * - Lambda init executes second (if defined)
     * - Snapshots are merged with lambda-level taking precedence
     *
     * **Requirements**: 18.1, 18.3, 18.6, 9.1, 9.2, 9.4, 4.1
     *
     * @param definition - Lambda definition with handler and dependencies (supports both formats)
     * @param container - Shared container instance (must be fully initialized)
     * @param microserviceDefinition - Optional microservice definition for microservice-level init
     * @returns Lambda handler class instance ready for AWS Lambda runtime
     * @throws Error if container is not ready or dependencies cannot be resolved
     *
     * @example
     * ```typescript
     * // Array-based ties (legacy - deprecated)
     * const arrayLambdaDef: LambdaDefinition = {
     *   id: 'charge',
     *   ties: [PaymentsService, BillingService],
     *   handler: (ties) => async (event, context) => {
     *     return await ties.paymentsService.processCharge(event.body);
     *   }
     * };
     *
     * // Object-based ties (new pattern - recommended)
     * const objectLambdaDef: LambdaDefinition = {
     *   id: 'charge',
     *   ties: { paymentsService: PaymentsService, billingService: BillingService },
     *   handler: async (event, context) => {
     *     return await event.ties.paymentsService.processCharge(event.body);
     *   }
     * };
     *
     * // With init function
     * const initLambdaDef: LambdaDefinition = {
     *   id: 'charge',
     *   ties: { paymentsService: PaymentsService },
     *   init: async (ties) => {
     *     const client = await ties.paymentsService.getClient();
     *     return { stripeClient: client };
     *   },
     *   handler: async (event, context) => {
     *     // event.snapshot.stripeClient is available
     *     return await event.snapshot.stripeClient.charge(event.body);
     *   }
     * };
     *
     * const handler = factory.create(lambdaDef, container);
     * // Or with microservice definition
     * const handler = factory.create(lambdaDef, container, microserviceDef);
     * ```
     */
    create(definition: LambdaDefinition, container: PureContainer<string>, microserviceDefinition?: MicroserviceDefinition): RuntimeWebLambdaHandler;
    /**
     * Inject dependencies from PureContainer using appropriate key strategy.
     *
     * Supports both object-based and array-based ties formats:
     * - Object-based: Uses property names as keys (e.g., { userService: UsersService })
     * - Array-based: Uses hash-based keys for backward compatibility
     *
     * **Requirements**: 7.1, 7.2, 6.1, 6.2, 18.2, 18.4, 1.5, 10.5, 9.1, 9.2
     *
     * @param definition - Lambda definition containing ties (object or array format)
     * @param container - Shared container instance with registered services
     * @returns Object with dependencies using appropriate keys
     * @throws Error if any dependency cannot be resolved or ties format is invalid
     *
     * @example
     * ```typescript
     * // Object-based ties (new pattern)
     * const objTies = { userService: UsersService, configService: ConfigService };
     * const objTies = factory.injectDependencies(objDefinition, container);
     * // Result: { userService: UsersService instance, configService: ConfigService instance }
     *
     * // Array-based ties (legacy pattern)
     * const arrTies = [PaymentsService, BillingService];
     * const arrTies = factory.injectDependencies(arrDefinition, container);
     * // Result: { 'n8Q64eDD-CMqOY5n6_7ecmzofI024-Ej': PaymentsService, ... }
     * ```
     */
    injectDependencies(definition: LambdaDefinition, container: PureContainer<string>): Record<string, unknown>;
    /**
     * Inject dependencies using object-based ties with meaningful keys.
     *
     * Uses property names directly as container keys without hashing.
     * Provides better debugging experience and type safety.
     *
     * **Requirements**: 7.1, 7.2, 6.1, 6.3, 1.5, 10.5, 9.1, 9.2
     *
     * @param definition - Lambda definition with object-based ties (supports both definition types)
     * @param container - Shared container instance
     * @returns Object with dependencies using property names as keys
     * @throws Error if any dependency cannot be resolved or ties validation fails
     */
    private injectObjectBasedDependencies;
    /**
     * Legacy array-based dependency injection (maintains backward compatibility).
     *
     * Resolves class references to service instances using PureContainer.run()
     * with stable hash-based keys. Uses metadata when available for consistent
     * hash computation, falling back to runtime hash computation if needed.
     *
     * **DEPRECATED**: This method supports legacy array-based ties for backward
     * compatibility. New code should use object-based ties instead.
     *
     * **Requirements**: 18.2, 18.4, 9.2, 4.5
     *
     * @param definition - Lambda definition containing ties classes array (supports both definition types)
     * @param container - Shared container instance with registered services
     * @returns Object with hash keys containing resolved dependencies
     * @throws Error if any dependency cannot be resolved
     */
    private injectArrayBasedDependencies;
    /**
     * Wrap a handler function with logging and error handling.
     *
     * Adds structured logging for Lambda invocation start/end, error handling
     * that catches and logs exceptions, and timing information. Returns a
     * wrapped handler that maintains the same signature as the original.
     *
     * @param handler - Original Lambda handler function
     * @param metadata - Lambda metadata for logging context
     * @returns Wrapped handler with logging and error handling
     *
     * @example
     * ```typescript
     * const wrappedHandler = factory.wrapHandler(
     *   async (event, context) => { return { success: true }; },
     *   { id: 'payments.charge', service: 'payments' }
     * );
     * ```
     */
    wrapHandler(handler: (event: unknown, context: unknown) => Promise<unknown>, metadata: {
        id: string;
        service: string;
    }): (event: unknown, context: unknown) => Promise<unknown>;
    /**
     * Convert class name to camelCase for dependency object keys.
     *
     * Converts PascalCase class names to camelCase property names for the
     * dependency injection object. This provides a consistent naming convention
     * for injected dependencies.
     *
     * @param className - PascalCase class name
     * @returns camelCase property name
     *
     * @example
     * ```typescript
     * factory.toCamelCase('PaymentsService'); // 'paymentsService'
     * factory.toCamelCase('BillingService');  // 'billingService'
     * factory.toCamelCase('ConfigService');   // 'configService'
     * ```
     */
    private toCamelCase;
    /**
     * Validate container state before handler creation.
     *
     * Ensures the container is properly initialized and contains all required
     * dependencies for the Lambda definition. Supports both array-based and
     * object-based ties formats.
     *
     * **Requirements**: 18.3, 9.1, 9.2
     *
     * @param container - Container to validate
     * @param definition - Lambda definition with required dependencies (supports both formats)
     * @throws Error if container is not ready or missing dependencies
     */
    private validateContainerState;
    /**
     * Ensure dependency metadata is loaded.
     *
     * Loads metadata from file if not already loaded. This metadata provides
     * stable hash keys for dependency resolution.
     */
    private ensureMetadataLoaded;
    /**
     * Get hash key for a class, using metadata when available.
     *
     * **Requirements**: 18.2
     *
     * @param classRef - Class constructor reference
     * @returns Stable hash key for the class
     */
    private getHashKeyForClass;
    /**
     * Get list of available services in container for error reporting.
     *
     * @param container - Container to inspect
     * @returns Array of available service identifiers
     */
    private getAvailableServices;
    /**
     * Validate ties object structure and content.
     *
     * **Requirements**: 1.5, 10.5
     *
     * @param tiesObject - Ties object to validate
     * @param lambdaId - Lambda ID for error context
     * @throws Error if ties object is invalid
     */
    private validateTiesObject;
    /**
     * Validate individual ties property.
     *
     * **Requirements**: 1.5, 10.5
     *
     * @param propertyName - Property name in ties object
     * @param value - Property value (should be constructor function)
     * @param lambdaId - Lambda ID for error context
     * @throws Error if property is invalid
     */
    private validateTiesProperty;
}
