import { PureContainer } from '@worktif/utils';
import { LambdaPipeline } from '../pipelines/lambda-pipeline';
import type { BundleDiagnostics, RuntimeBundle } from './runtime-bundle.interface';
import type { MicroserviceDefinition } from '../../../lib/runtime-web/types/microservice.types';
import type { RuntimeThreads } from '../../../lib/runtime.types';
/**
 * Error class for MicroserviceBundle-specific errors.
 */
export declare class MicroserviceBundleError extends Error {
    readonly microserviceName: string;
    readonly cause?: Error | undefined;
    constructor(microserviceName: string, message: string, cause?: Error | undefined);
}
/**
 * Extended diagnostics for MicroserviceBundle including microservice-specific info.
 */
export interface MicroserviceBundleDiagnostics extends BundleDiagnostics {
    /**
     * Name of the microservice this bundle belongs to
     */
    microserviceName: string;
    /**
     * Hash key to handler name mapping for debugging
     */
    hashToNameMap: Record<string, string>;
    /**
     * A mapping of hash values to their respective service names.
     * This map is used to associate a specific hash identifier with a service name
     * for internal reference or lookup purposes.
     *
     * Key: A string representing the unique hash value.
     * Value: A string representing the name of the corresponding service.
     */
    hashToServiceNameMap: Record<string, string>;
    /**
     * A mapping object that associates unique hash strings to their respective handler service names.
     * Each key in the record represents a hash string, while the associated value is the name
     * of the handler service that corresponds to that hash.
     *
     * This mapping can be used for efficient lookup of handler services based on their unique hash identifiers.
     */
    hashToHandlersServiceNameMap: Record<string, string>;
    /**
     * Number of object-based ties detected in this microservice
     */
    objectBasedTiesCount?: number;
    /**
     * Whether enhanced DI pattern is active (object-based ties present)
     */
    enhancedDiPattern?: boolean;
    /**
     * List of object-based lambda handlers with their meaningful keys
     */
    objectBasedHandlers?: Array<{
        handlerName: string;
        hashKey: string;
        meaningfulKeys: string[];
    }>;
    /**
     * Migration status information
     */
    migrationInfo?: {
        arrayBasedCount: number;
        objectBasedCount: number;
        totalHandlers: number;
        migrationProgress: number;
    };
}
/**
 * MicroserviceBundle - Isolated bundle for a single microservice.
 *
 * Each microservice gets its own MicroserviceBundle containing:
 * - Isolated PureContainer with hash-based service keys
 * - Pre-bound handlers keyed by hash32Base64Url
 * - Lambda does NOT know its microservice - it's already in the Layer
 *
 * This follows the architectural principle:
 * - One Microservice = One Lambda Layer = One DI Container
 * - Lambda calls `getHandler(hashKey)` where hashKey is computed at build time
 * - All resolution uses hash32Base64Url keys, NOT string IDs
 *
 * **Requirements**: 2.1, 2.2, 3.4, 3.6
 *
 * @example
 * ```typescript
 * const paymentsBundle = new MicroserviceBundle('payments', definition, container);
 *
 * // Get handler using hash key computed at build time
 * const hashKey = hash32Base64Url(handlerCode.toString());
 * const chargeHandler = paymentsBundle.getHandler(hashKey);
 *
 * // Execute handler
 * const result = await chargeHandler(event, context);
 * ```
 */
export declare class MicroserviceBundle implements RuntimeBundle {
    /**
     * Name of the microservice this bundle belongs to
     */
    private readonly microserviceName;
    /**
     * Microservice definition with ties and lambdas
     */
    private readonly definition;
    /**
     * Isolated DI container for this microservice
     * All services registered with hash32Base64Url keys
     */
    private readonly container;
    /**
     * Logger instance for enhanced diagnostics
     */
    private readonly logger;
    /**
     * Pre-bound handlers by hash key
     * Format: { [hash32Base64Url(handlerCode)]: boundHandler }
     */
    private readonly handlers;
    /**
     * Hash key to handler name mapping for debugging
     */
    private readonly hashToNameMap;
    /**
     * A mapping between hash values and corresponding service names.
     *
     * This map uses a `string` hash as the key and associates it with a
     * `string` service name. It is primarily used to resolve or identify
     * service names based on their unique hashed identifiers.
     *
     * Key:
     * - A `string` representing a hash, typically used as a unique identifier.
     *
     * Value:
     * - A `string` representing the name of the service associated with the hash.
     */
    private readonly hashToServiceNameMap;
    /**
     * A map object that associates hash values with corresponding service names.
     *
     * This map is used to link specific hash keys (string format) to their
     * handler service names (also in string format). It provides a way to
     * efficiently retrieve the service name associated with a given hash.
     *
     * Key Type: string - Represents the hash key.
     * Value Type: string - Represents the service name associated with the hash.
     */
    private readonly hashToHandlersServiceNameMap;
    /**
     * Initialization timestamp for diagnostics
     */
    private readonly initializationStartTime;
    /**
     * Initialization end time for diagnostics
     */
    private initializationEndTime?;
    /**
     * Create a new MicroserviceBundle with isolated DI container.
     *
     * @param microserviceName - Name of the microservice (e.g., 'payments')
     * @param definition - Microservice definition with ties and lambdas > @note: definition: { ties: [...], lambdas: [...] }
     * @param container - Pre-created PureContainer instance for this microservice
     */
    constructor(microserviceName: string, definition: MicroserviceDefinition, container: PureContainer<string>);
    /**
     * Get the microservice-specific DI container.
     *
     * **Requirements**: 2.3
     *
     * @returns Isolated PureContainer for this microservice
     */
    getContainer(): PureContainer<string>;
    /**
     * Get the Lambda pipeline instance.
     *
     * Creates a new pipeline with this microservice's container.
     *
     * **Requirements**: 2.2
     *
     * @returns Lambda pipeline instance with microservice container
     */
    getPipeline(): LambdaPipeline;
    /**
     * Get handler by Lambda ID (RuntimeBundle interface compatibility).
     *
     * This method maintains compatibility with the RuntimeBundle interface
     * while internally using hash-based resolution.
     *
     * Supports two calling conventions for backward compatibility:
     * - getHandler(lambdaId) - legacy sync call
     * - getHandler(runtimeThreads, lambdaId) - new async call
     *
     * **Requirements**: 2.1, 2.2, 3.4
     *
     * @param runtimeThreadsOrLambdaId - RuntimeThreads object OR Lambda ID for backward compatibility
     * @param lambdaId - Lambda ID (can be hash key or short ID for backward compatibility)
     * @returns Bound handler function
     * @throws Error if handler not found
     */
    getHandler(runtimeThreadsOrLambdaId: RuntimeThreads | string, lambdaId?: string): Function;
    /**
     * Get the number of handlers in this bundle (for testing).
     *
     * @returns Number of registered handlers
     */
    getHandlerCount(): number;
    /**
     * Get handler by hash key directly.
     *
     * Lambda calls `getHandlerByHash(hashKey)` where hashKey is computed at build time
     * using hash32Base64Url(handlerCode.toString()).
     *
     * **Requirements**: 2.1, 2.2, 3.4
     *
     * @param hashKey - Hash key computed via hash32Base64Url
     * @returns Bound handler function
     * @throws Error if handler not found
     */
    getHandlerByHash(hashKey: string): Function;
    /**
     * Validate bundle completeness.
     *
     * Validates that all microservice dependencies are registered and
     * all Lambda handlers are created correctly using hash-based keys.
     *
     * **Requirements**: 2.5
     *
     * @throws Error if bundle validation fails
     */
    validateBundle(): void;
    /**
     * Get diagnostic information including hash mappings and object-based ties info.
     *
     * **Requirements**: 3.6, 8.5
     *
     * @returns Microservice-specific diagnostic information with enhanced DI pattern details
     */
    getDiagnostics(): MicroserviceBundleDiagnostics;
    /**
     * Get the microservice name.
     *
     * @returns Name of the microservice this bundle belongs to
     */
    getMicroserviceName(): string;
    /**
     * Get all available hash keys.
     *
     * @returns Array of hash keys available in this bundle
     */
    getAvailableHashKeys(): string[];
    /**
     * Check if a handler exists for the given hash key.
     *
     * @param hashKey - Hash key to check
     * @returns True if handler exists
     */
    hasHandler(hashKey: string): boolean;
    /**
     * Get handler name from hash key (for debugging).
     *
     * @param hashKey - Hash key
     * @returns Handler name or undefined if not found
     */
    getHandlerName(hashKey: string): string | undefined;
    /**
     * Register all Ties classes from the microservice definition.
     *
     * Enhanced to support both array-based and object-based ties registration:
     * - Array-based (legacy): Uses hash-based keys for services
     * - Object-based (new): Uses property names as meaningful keys
     *
     * **Requirements**: 4.1, 4.2, 8.1, 6.1, 6.5
     *
     * @note: definition: { ties: [...], lambdas: [...] }
     *
     * @private
     */
    private registerTies;
    /**
     * Register object-based ties with property names as keys.
     *
     * Uses meaningful property names instead of hash-based keys for better
     * debugging and developer experience. Handles dependencies between services
     * by resolving dependency property names to their registered keys.
     *
     * **Requirements**: 8.1, 6.1, 6.5
     *
     * @param tiesClassName - Name of the Ties class for error reporting
     * @param registerData - Object-based register data with property names as keys
     * @private
     */
    private registerObjectBasedTies;
    /**
     * Register array-based ties with hash-based keys (legacy).
     *
     * Maintains backward compatibility with existing array-based ties registration.
     *
     * **Requirements**: 9.1, 9.2
     *
     * @param tiesClassName - Name of the Ties class for error reporting
     * @param registerArray - Array-based register data
     * @private
     */
    private registerArrayBasedTies;
    /**
     * Check if register data is object-based format.
     *
     * @param registerData - Register data to check
     * @returns True if object-based, false if array-based or invalid
     * @private
     */
    private isObjectBasedRegister;
    /**
     * Register Service classes from Lambda definitions.
     *
     * This method processes Service classes referenced in LambdaDefinition.ties
     * and registers them in the DI container using hash-based keys.
     * These are actual business logic classes, not DI configuration classes.
     *
     * Enhanced to support both array-based and object-based ties formats.
     *
     * @param definition - Microservice definition containing Lambda definitions
     * @throws Error if Service class registration fails
     * @private
     */
    private registerLambdaServices;
    /**
     * Create handlers for all Lambdas using enhanced LambdaHandlerFactory.
     *
     * This method creates pre-bound handlers for all Lambda functions in the microservice
     * using the enhanced LambdaHandlerFactory that supports both array-based and object-based ties.
     * Each handler is keyed by a hash computed via hash32Base64Url(handlerCode.toString()).
     *
     * **Requirements**: 2.4, 2.5, 8.1, 8.2, 8.3
     *
     * @throws Error if handler creation fails or hash collision detected
     * @private
     */
    private createHandlers;
    /**
     * Resolve dependencies from Ties classes using class name keys.
     *
     * This method resolves all Lambda dependencies using the class name
     * converted to camelCase as the key. This matches how Ties classes
     * typically register services.
     *
     * **Requirements**: 2.4, 2.5, 4.4, 4.5
     *
     * @param tiesClasses - Array of Service class constructors (not Ties classes)
     * @returns Record of resolved dependencies keyed by camelCase class name
     * @throws Error if any dependency cannot be resolved
     * @private
     */
    private resolveDependencies;
    /**
     * Get list of available services in the container for debugging.
     *
     * @returns Array of service identifiers available in the container
     * @private
     */
    private getAvailableServices;
    /**
     * Check if a service can be resolved by hash key.
     *
     * @param hashKey - Hash key to check
     * @returns True if service is resolvable
     * @private
     */
    private canResolveService;
    /**
     * Validate that all registered Ties are resolvable by their hash keys.
     *
     * **Requirements**: 4.2, 4.3
     *
     * @param registeredHashKeys - Set of hash keys that should be registered
     * @private
     */
    private validateTiesRegistration;
    /**
     * Compute hash key for a Ties class (service).
     */
    private computeServiceHashKey;
    /**
     * Compute hash key for a Lambda handler.
     */
    private computeHandlerHashKey;
    /**
     * Get initialization time in milliseconds.
     *
     * @returns Initialization time
     * @private
     */
    private getInitializationTime;
}
