import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as apigatewayv2 from 'aws-cdk-lib/aws-apigatewayv2';
import type { MicroserviceDefinition, VpcConfig } from '../../../lib/runtime-web/types';
import type { RuntimeAwakeFallbackMode } from '../../../lib/runtime-web/runtime-awake';
import type { IResourceEntity, IIntegrationStrategy, InjectOptions } from '../../../lib/runtime-web/types/declarative-api';
import { MicroserviceRegistrar } from '../../../core/runtime-web/registrar';
import type { RuntimeInfraStack } from '../../runtime-infra-stack';
import type { RuntimeAwakeStack } from '../../runtime-web/runtime-awake/runtime-awake-stack';
import { MicroserviceLayerBundleResult, MicroserviceLayerOptions } from '../../utils';
/**
 * Properties for RuntimeWebStack
 */
export interface RuntimeWebStackProps extends cdk.StackProps {
    /**
     * Deployment stage (dev, staging, prod)
     */
    stage: 'dev' | 'staging' | 'prod';
    /**
     * Service name for resource naming
     */
    serviceName: string;
    /**
     * Reference to Infra stack for cross-stack references
     */
    infraStack: RuntimeInfraStack;
    /**
     * Path to user's application entry point
     * @example './src/index.tsx'
     */
    appEntryPoint?: string;
    /**
     * Microservice registry with service definitions
     */
    register: Record<string, MicroserviceDefinition>;
    /**
     * API exposure mode
     * @default 'apiGateway'
     */
    apiMode?: 'apiGateway' | 'lambdaUrl';
    /**
     * Default Lambda memory size in MB
     * @default 512
     */
    lambdaMemorySize?: number;
    /**
     * Default Lambda timeout in seconds
     * @default 30
     */
    lambdaTimeout?: number;
    /**
     * Enable Lambda warmup
     * @default false
     */
    enableWarmup?: boolean;
    /**
     * VPC configuration for Lambda functions
     */
    vpc?: VpcConfig;
    /**
     * Global environment variables for all Lambda functions
     */
    environment?: Record<string, string>;
    /**
     * Runtime Awake (Live Dev) configuration.
     *
     * When enabled, deploys Proxy Lambda functions for local debugging.
     * The Proxy Lambda intercepts API Gateway requests and routes them
     * to the developer's local CLI via AWS IoT Core MQTT.
     *
     * **Requirements**: 8.1
     *
     * @example
     * ```typescript
     * runtimeAwake: {
     *   enabled: true,
     *   runtimeAwakeStack: runtimeAwakeStack,
     *   fallbackMode: 'execute',
     *   defaultDevId: 'john.doe',
     * }
     * ```
     */
    runtimeAwake?: {
        /**
         * Enable Live Dev mode.
         * When true, Proxy Lambda functions are deployed instead of original handlers.
         */
        enabled: boolean;
        /**
         * Reference to RuntimeAwakeStack containing infrastructure resources.
         * Required when enabled is true.
         */
        runtimeAwakeStack: RuntimeAwakeStack;
        /**
         * Fallback behavior when no active session exists.
         * - 'execute': Run the original handler in the cloud
         * - 'error': Return 503 "Live dev session not connected"
         *
         * @default 'execute'
         */
        fallbackMode?: RuntimeAwakeFallbackMode;
        /**
         * Default Dev_ID for session lookup when not provided in request.
         * Used as fallback when X-Runtime-Awake-Id header and authorizer context are not present.
         */
        defaultDevId?: string;
        /**
         * Timeout buffer in seconds (subtracted from Lambda timeout).
         * @default 5
         */
        timeoutBuffer?: number;
    };
}
/**
 * RuntimeWebStack - CDK stack for Runtime Web Core microservices.
 *
 * Creates Lambda functions and API Gateway from microservice definitions.
 * Extends the existing Runtime infrastructure with microservice support.
 *
 * **Features**:
 * - Automatic Lambda function creation from LambdaDefinition
 * - API Gateway with HTTP routes for Lambda endpoints
 * - Environment variable injection (LAMBDA_ID, SERVICE_NAME, STAGE)
 * - VPC support for private resources
 * - Lambda warmup for reduced cold starts
 *
 * **Requirements**: REQ-11, REQ-13, REQ-14
 *
 * @example
 * ```typescript
 * const runtimeWebStack = new RuntimeWebStack(app, 'my-app-runtime-dev', {
 *   stage: 'dev',
 *   serviceName: 'my-app',
 *   infraStack,
 *   register: {
 *     payments: {
 *       ties: [PaymentsTies],
 *       lambdas: [chargeHandler, refundHandler]
 *     }
 *   },
 *   apiMode: 'apiGateway',
 *   lambdaMemorySize: 512,
 *   lambdaTimeout: 30
 * });
 * ```
 */
export declare class RuntimeWebStack extends cdk.Stack {
    /**
     * Map of Lambda functions by Lambda ID
     */
    readonly lambdaFunctions: Map<string, lambda.Function>;
    /**
     * Map of Lambda Layers by microservice name.
     * Each microservice gets its own Lambda Layer with its own MicroserviceBundle.
     */
    readonly microserviceLayers: Map<string, lambda.LayerVersion>;
    /**
     * Map of Proxy Lambda functions by Lambda ID.
     * Only populated when runtimeAwake is enabled.
     */
    readonly proxyLambdaFunctions: Map<string, lambda.Function>;
    /**
     * API Gateway HttpApi (if apiMode is 'apiGateway')
     */
    readonly apiGateway?: apigatewayv2.HttpApi;
    /**
     * API Gateway stage
     */
    readonly apiGatewayStage?: apigatewayv2.HttpStage;
    /**
     * Microservice registrar for DI container management
     */
    private readonly registrar;
    /**
     * Lambda builder construct
     */
    private readonly lambdaBuilder;
    /**
     * API Gateway builder construct
     */
    private readonly apiGatewayBuilder;
    /**
     * IAM role for Lambda execution
     */
    private readonly lambdaRole;
    constructor(scope: Construct, id: string, props: RuntimeWebStackProps);
    /**
     * Register microservices and build DI containers.
     *
     * Processes each microservice definition to create PureContainer instances
     * and establish Lambda-to-service mappings.
     *
     * @param register - Microservice registry
     * @private
     */
    private registerMicroservices;
    /**
     * Create Lambda Layers for each microservice.
     *
     * Each microservice gets its own Lambda Layer containing:
     * - MicroserviceBundle with DI container
     * - All dependencies (Ties classes)
     * - Pre-created Lambda instances with bound handlers
     *
     * This follows the architectural principle: One Microservice = One Lambda Layer = One DI Container
     *
     * @param props - Stack properties
     * @private
     */
    private createMicroserviceLayers;
    /**
     * Constructs and returns a sanitized build directory string for the given microservice layer.
     *
     * @param props - The properties of the runtime web stack, including service name and stage.
     * @param microserviceName - The name of the microservice for which the layer directory is being constructed.
     * @return The sanitized name of the layer build directory.
     */
    private layerBuildDirectory;
    /**
     * Create a Lambda Layer for a specific microservice.
     *
     * The Layer contains the MicroserviceBundle with:
     * - DI container created at bundle load time
     * - All Lambda handlers as pre-bound methods
     * - No DI resolution on invoke
     *
     * @param props - Stack properties
     * @param microserviceName - Name of the microservice
     * @param definition - Microservice definition
     * @returns Lambda LayerVersion
     * @private
     */
    private createMicroserviceLayer;
    /**
     * Create Lambda functions for all registered microservices.
     *
     * Iterates through all microservice definitions and creates Lambda
     * functions for each LambdaDefinition with proper environment variables.
     * Each Lambda function is attached to its microservice's Lambda Layer.
     *
     * @param props - Stack properties
     * @private
     */
    private createLambdaFunctions;
    /**
     * Create Proxy Lambda functions for Runtime Awake (Live Dev).
     *
     * When Runtime Awake is enabled, creates ProxyLambdaConstruct for each
     * original Lambda function. The proxy functions intercept requests and
     * route them to the developer's local CLI via IoT Core.
     *
     * **Requirements**: 8.2, 8.3
     *
     * @param props - Stack properties with runtimeAwake configuration
     * @private
     */
    private createProxyLambdaFunctions;
    /**
     * Build global environment variables for Lambda functions.
     *
     * Creates environment variables that are shared across all Lambda functions
     * including infrastructure references from the Infra stack.
     *
     * @param props - Stack properties
     * @returns Environment variables record
     * @private
     */
    private buildGlobalEnvironment;
    /**
     * Create CloudFormation outputs for stack resources.
     *
     * @param props - Stack properties
     * @private
     */
    private createOutputs;
    /**
     * Get Lambda function by ID.
     *
     * @param lambdaId - Full Lambda ID (e.g., 'payments.charge')
     * @returns Lambda function or undefined
     */
    getLambdaFunction(lambdaId: string): lambda.Function | undefined;
    /**
     * Get all Lambda IDs.
     *
     * @returns Array of Lambda IDs
     */
    getLambdaIds(): string[];
    /**
     * Get the microservice registrar.
     *
     * @returns MicroserviceRegistrar instance
     */
    getRegistrar(): MicroserviceRegistrar;
    /**
     * Get Lambda Layer for a microservice.
     *
     * @param serviceName - Name of the microservice
     * @returns Lambda LayerVersion or undefined
     */
    getMicroserviceLayer(serviceName: string): lambda.LayerVersion | undefined;
    /**
     * Get all microservice names that have Lambda Layers.
     *
     * @returns Array of microservice names
     */
    getMicroserviceNames(): string[];
    /**
     * Get Proxy Lambda function by ID.
     *
     * Returns the proxy function for the given Lambda ID when Runtime Awake is enabled.
     *
     * @param lambdaId - Full Lambda ID (e.g., 'payments.charge')
     * @returns Proxy Lambda function or undefined
     */
    getProxyLambdaFunction(lambdaId: string): lambda.Function | undefined;
    /**
     * Get all Proxy Lambda IDs.
     *
     * @returns Array of Proxy Lambda IDs
     */
    getProxyLambdaIds(): string[];
    /**
     * Check if Runtime Awake (Live Dev) is enabled.
     *
     * @returns True if proxy functions are deployed
     */
    isRuntimeAwakeEnabled(): boolean;
    /**
     * Get the effective Lambda function for a given ID.
     *
     * Returns the proxy function if Runtime Awake is enabled,
     * otherwise returns the original function.
     *
     * @param lambdaId - Full Lambda ID (e.g., 'payments.charge')
     * @returns Lambda function (proxy or original) or undefined
     */
    getEffectiveLambdaFunction(lambdaId: string): lambda.Function | undefined;
    /**
     * Grant a Lambda function access to a resource using Integration_Strategy.
     *
     * Delegates permission granting to the provided strategy or uses FullAccessStrategy
     * by default. The strategy determines which IAM actions are granted.
     *
     * **Validates: Requirements 4.1, 4.3, 4.4**
     *
     * @param resource - The resource entity to grant access to
     * @param lambdaId - The Lambda ID (e.g., 'payments.charge')
     * @param strategy - Optional integration strategy (defaults to FullAccessStrategy)
     * @returns The IAM Grant object
     * @throws LambdaNotFoundError if lambdaId doesn't exist
     *
     * @example
     * ```typescript
     * // Grant full access (default)
     * runtimeWebStack.grantResourceAccess(usersTable, 'payments.charge');
     *
     * // Grant read-only access
     * runtimeWebStack.grantResourceAccess(usersTable, 'payments.charge', new ReadOnlyStrategy());
     * ```
     */
    grantResourceAccess(resource: IResourceEntity, lambdaId: string, strategy?: IIntegrationStrategy): iam.Grant;
    /**
     * Inject resource environment variables into a Lambda function.
     *
     * Uses consistent environment variable naming convention:
     * `{RESOURCE_TYPE}_{RESOURCE_ID}_{PROPERTY}`
     *
     * For example:
     * - `DYNAMODB_USERS_TABLE_NAME`
     * - `SQS_ORDERS_QUEUE_URL`
     * - `S3_ASSETS_BUCKET_NAME`
     *
     * **Validates: Requirements 4.2, 4.5**
     *
     * @param resource - The resource entity to inject identifiers for
     * @param lambdaId - The Lambda ID
     * @param options - Optional injection configuration
     * @throws LambdaNotFoundError if lambdaId doesn't exist
     *
     * @example
     * ```typescript
     * // Inject with default naming
     * runtimeWebStack.injectResourceEnv(usersTable, 'payments.charge');
     * // Results in: DYNAMODB_USERS_TABLE_NAME, DYNAMODB_USERS_TABLE_ARN
     *
     * // Inject with custom prefix
     * runtimeWebStack.injectResourceEnv(usersTable, 'payments.charge', {
     *   envVarPrefix: 'USERS_TABLE',
     * });
     * // Results in: USERS_TABLE_NAME, USERS_TABLE_ARN
     * ```
     */
    injectResourceEnv(resource: IResourceEntity, lambdaId: string, options?: InjectOptions): void;
    /**
     * Grant multiple resources access to a Lambda function.
     *
     * Grants access for all resources in the array, returning an array of
     * iam.Grant objects with the same length as the input array.
     *
     * **Validates: Requirements 4.6**
     *
     * @param resources - Array of resource entities
     * @param lambdaId - The Lambda ID
     * @param strategy - Optional integration strategy
     * @returns Array of IAM Grant objects
     * @throws LambdaNotFoundError if lambdaId doesn't exist
     *
     * @example
     * ```typescript
     * const grants = runtimeWebStack.grantResourceAccessBatch(
     *   [usersTable, ordersQueue, notificationsTopic],
     *   'payments.charge',
     *   new ReadOnlyStrategy(),
     * );
     * ```
     */
    grantResourceAccessBatch(resources: readonly IResourceEntity[], lambdaId: string, strategy?: IIntegrationStrategy): iam.Grant[];
    /**
     * Generate environment variable prefix from resource.
     *
     * Follows naming convention: {RESOURCE_TYPE}_{RESOURCE_ID}
     *
     * @param resource - The resource entity
     * @returns Environment variable prefix in UPPER_SNAKE_CASE
     * @private
     */
    private generateEnvVarPrefix;
    /**
     * Get environment variables for a resource.
     *
     * @param resource - The resource entity
     * @param prefix - Environment variable prefix
     * @param options - Injection options
     * @returns Record of environment variable names to values
     * @private
     */
    private getResourceEnvVars;
    /**
     * Apply IAM permissions to a Lambda function for a resource.
     *
     * @param resource - The resource entity
     * @param lambdaFunction - The Lambda function
     * @param actions - IAM actions to grant
     * @returns The IAM Grant object
     * @private
     */
    private applyResourcePermissions;
    /**
     * Get the ARN for a resource.
     *
     * @param resource - The resource entity
     * @returns The resource ARN
     * @private
     */
    private getResourceArn;
    /**
     * Build Lambda Layer bundles for multiple microservices.
     *
     * Creates separate Lambda Layer bundles for each microservice in the register.
     * Each bundle contains its own MicroserviceBundle with isolated DI container.
     *
     * @param register - Map of microservice names to their definitions
     * @param appEntryPoint - Path to the user's application entry point
     * @param stage
     * @param options - Additional build options
     * @returns Map of microservice names to their build results
     *
     * @important: this functions is bint to RuntimeWebStack instance during its call
     */
    buildAllMicroserviceLayerBundles(register: Record<string, MicroserviceDefinition>, stage: string, appEntryPoint?: string, options?: {
        minify?: boolean;
        sourcemap?: boolean;
    }): Map<string, MicroserviceLayerBundleResult>;
    /**
     * Build a Lambda Layer bundle for a specific microservice.
     *
     * Each microservice gets its own Lambda Layer containing:
     * - MicroserviceBundle with DI container (created at bundle load time)
     * - All dependencies (Ties classes)
     * - Pre-created Lambda instances with bound handlers
     * - node_modules/ with React, ReactDOM, React Router (peer ties)
     *
     * This follows the architectural principle:
     * - One Microservice = One Lambda Layer = One DI Container
     * - DI at bundle load time, NOT on invoke
     * - Handler = pre-bound method, invoke = just method call
     *
     * **Validates: Requirements 7.2, 7.4**
     *
     * @param options - Microservice layer options
     * @param definition
     * @returns Build result with bundle path and size
     */
    buildMicroserviceLayerBundle(options: MicroserviceLayerOptions, definition?: MicroserviceDefinition): MicroserviceLayerBundleResult;
}
