import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
import type { AuthConfig } from '../../../lib/runtime-web/types';
import type { RuntimeWebStackProps } from '../../runtime-web/stacks/runtime-web-stack';
import { RuntimeInfraResourceOptions, RuntimeInfraResources } from '../../interfaces';
/**
 * Properties for RestApiGatewayBuilder construct.
 *
 * Mirrors {@link ApiGatewayBuilderProps} for REST API (API Gateway v1).
 */
export interface RestApiGatewayBuilderProps {
    /**
     * Deployment stage
     */
    stage: 'dev' | 'staging' | 'prod';
    /**
     * Service name for resource naming
     */
    serviceName: string;
    /**
     * Allowed origins for CORS
     * @default ['*'] for dev/staging, specific domains for prod
     */
    allowedOrigins?: string[];
    /**
     * Custom domain configuration
     */
    domain?: {
        rootDomain: string;
        subdomain?: string;
        certificateArn?: string;
        hostedZoneId?: string;
    };
    /**
     * Default authorization for all routes.
     *
     * When specified, this authorizer will be applied to all routes
     * that don't have explicit auth configuration.
     *
     * Routes can override this by specifying their own auth config,
     * or disable auth entirely with `auth: 'none'` or `auth: { type: 'none' }`.
     */
    defaultAuth?: AuthConfig;
}
/**
 * RestApiGatewayBuilder - CDK construct for building REST API Gateway (v1) from Lambda definitions.
 *
 * Creates REST API Gateway with resources and methods for Lambda functions based on their
 * HttpIntegration configuration. Supports CORS, authentication, and custom domains.
 *
 * REST API (v1) provides features not available in HTTP API (v2):
 * - API keys and usage plans
 * - Request/response validation and transformation
 * - WAF integration
 * - Caching
 * - More granular throttling
 *
 * **Features**:
 * - Automatic resource/method creation from HttpIntegration
 * - CORS configuration via defaultCorsPreflightOptions
 * - Authentication mapping (none, jwt/token, iam, cognito, custom)
 * - Custom domain support
 * - Named deployment stages
 *
 * **Requirements**: REQ-14
 *
 * @example
 * ```typescript
 * const builder = new RestApiGatewayBuilder(this, 'RestApiGatewayBuilder', {
 *   stage: 'dev',
 *   serviceName: 'my-app'
 * });
 *
 * const { api, deploymentStage } = builder.createRestApiGateway(lambdaFunctions, props);
 * ```
 */
export declare class RestApiGatewayBuilder extends Construct implements RuntimeInfraResources {
    private readonly props;
    /**
     * Microservice registrar for DI container management
     */
    private readonly registrar;
    /**
     * Cache for authorizer instances to enable reuse across routes.
     *
     * REST API authorizers with equivalent configuration are cached and reused
     * to avoid creating duplicate CDK resources.
     *
     * Cache key format:
     * - JWT/Token: `token:{lambdaArn}:{identitySource}`
     * - IAM: `iam`
     * - Cognito: `cognito:{userPoolArns}:{identitySource}`
     * - Custom: `custom:{lambdaArn}:{identitySource}`
     */
    private readonly authorizerCache;
    /**
     * Cache for API Gateway resources by path to avoid duplicate resource creation.
     * REST API requires explicit resource tree construction.
     */
    private readonly resourceCache;
    constructor(scope: Construct, id: string, props: RestApiGatewayBuilderProps);
    /**
     * Create REST API Gateway with resources and methods for all Lambda functions.
     *
     * Creates a REST API with resources based on the HttpIntegration configuration
     * of each Lambda definition. Only creates methods for Lambdas with HTTP config.
     *
     * @param lambdaFunctions - Map of Lambda functions by ID
     * @param props - RuntimeWebStack properties
     * @returns Object with REST API and deployment stage
     */
    createRestApiGateway(lambdaFunctions: Map<string, lambda.Function>, props: RuntimeWebStackProps): {
        api: apigateway.RestApi;
        deploymentStage: apigateway.Stage;
    };
    /**
     * Get or create an API Gateway resource for the given path.
     *
     * REST API requires explicit resource tree construction. This method
     * builds the resource tree incrementally, caching intermediate resources.
     *
     * For path `/api/users/{id}`, creates:
     * - `/api` resource (if not exists)
     * - `/api/users` resource (if not exists)
     * - `/api/users/{id}` resource (if not exists)
     *
     * @param api - REST API instance
     * @param resourcePath - Full resource path (e.g., '/api/users/{id}')
     * @returns The leaf API Gateway resource
     * @private
     */
    private getOrCreateResource;
    /**
     * Create a resource and method for a Lambda function.
     *
     * Creates the resource tree for the path and adds an HTTP method
     * with Lambda proxy integration and optional authorizer.
     *
     * @param api - REST API instance
     * @param lambdaFn - Lambda function to integrate
     * @param http - HTTP integration configuration
     * @param lambdaId - Lambda ID for naming
     * @private
     */
    private createResourceAndMethod;
    /**
     * Build method options including authorization configuration.
     *
     * @param auth - Authentication type or configuration
     * @param routePath - Route path for error context
     * @returns Method options for the API Gateway method
     * @private
     */
    private buildMethodOptions;
    /**
     * Build method options for JWT authorization.
     *
     * REST API does not have a native JWT authorizer like HTTP API.
     * JWT validation is implemented via a Token Authorizer (custom Lambda).
     *
     * If the user provides an `authorizerLambda` on the JWT config (extended pattern),
     * it is used directly. Otherwise, a warning is logged and IAM auth is used as fallback.
     *
     * **Note**: For pure JWT validation on REST API, consider using Cognito auth type
     * or providing a custom authorizer Lambda that validates JWT tokens.
     *
     * @param config - JWT auth configuration
     * @param routePath - Route path for error context
     * @returns Method options with Token authorizer
     * @private
     */
    private buildJwtMethodOptions;
    /**
     * Build method options for Cognito authorization.
     *
     * REST API has native CognitoUserPoolsAuthorizer support.
     * This is the recommended auth type for Cognito on REST API.
     *
     * @param config - Cognito auth configuration
     * @param routePath - Route path for error context
     * @returns Method options with Cognito authorizer
     * @private
     */
    private buildCognitoMethodOptions;
    /**
     * Build method options for custom Lambda authorization.
     *
     * REST API supports Token and Request authorizers.
     * Maps to TokenAuthorizer by default (header-based identity source).
     *
     * @param config - Custom auth configuration
     * @param routePath - Route path for error context
     * @returns Method options with custom authorizer
     * @private
     */
    private buildCustomMethodOptions;
    /**
     * Map HTTP API v2 identity source format to REST API v1 format.
     *
     * HTTP API: `$request.header.Authorization`
     * REST API: `method.request.header.Authorization`
     *
     * @param identitySources - HTTP API v2 identity sources
     * @returns REST API v1 identity source string
     * @private
     */
    private mapIdentitySource;
    /**
     * Generate cache key for authorizer configuration.
     *
     * Creates a deterministic cache key based on the auth configuration
     * to enable authorizer reuse across routes with equivalent config.
     *
     * @param config - Auth configuration
     * @returns Cache key string
     * @private
     */
    private getAuthorizerCacheKey;
    /**
     * Generate a unique authorizer ID from cache key.
     *
     * @param cacheKey - Cache key to hash
     * @returns Short unique identifier
     * @private
     */
    private generateAuthorizerId;
    /**
     * Create CORS options for REST API Gateway.
     *
     * @param allowedOrigins - Array of allowed origins
     * @returns CORS preflight options for REST API
     * @private
     */
    private createCorsOptions;
    /**
     * Generates a signature for the provided region.
     *
     * @param region - The region string
     * @returns The generated region signature
     * @private
     */
    private getRegionSignature;
    /**
     * Generates a resource name by concatenating service name, resource name,
     * simplified region, and stage with hyphens as separators.
     *
     * @param params - Resource naming parameters
     * @returns The concatenated resource name
     */
    resourceName({ name, serviceName, stage, region }: RuntimeInfraResourceOptions): string;
}
