import { Function as LambdaFunction } from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { KataProps, LicensingResponse, TransformationConfig } from './types';
import { LicensingService } from './licensing';
/**
 * Options for the kata wrapper, extending KataProps with internal options.
 */
export interface KataWrapperOptions extends KataProps {
    /**
     * Optional: Custom licensing service for testing.
     * If not provided, the default HTTP licensing service will be used.
     * @internal
     */
    licensingService?: LicensingService;
    /**
     * Custom bundle path.
     * If not specified, uses the default /opt/js_runtime/bundle.js
     */
    bundlePath?: string;
    /**
     * Path to middleware TypeScript/JavaScript file.
     * The file will be compiled with esbuild and included in the config layer.
     * The middleware must export a function: (bundle, context) => handler
     */
    middlewarePath?: string;
    /**
     * Inline handler resolver function.
     * This TypeScript function will be serialized, compiled with esbuild,
     * and included in the config layer as middleware.js
     *
     * The function receives the loaded bundle and context with originalHandler,
     * and must return the handler function.
     *
     * Note: The function must be pure (no closures over external variables)
     * because it will be serialized via .toString()
     *
     * @example
     * ```typescript
     * kata(myFunction, {
     *   handlerResolver: (bundle, ctx) => {
     *     const handlerName = ctx.originalHandler.split('.').pop();
     *     return bundle[handlerName];
     *   }
     * });
     * ```
     */
    handlerResolver?: (bundle: unknown, context: {
        originalHandler: string;
    }) => Function;
}
/**
 * Result of the kata transformation.
 */
export interface KataResult {
    /**
     * Whether the Lambda was transformed.
     */
    transformed: boolean;
    /**
     * The licensing response from the licensing service.
     */
    licensingResponse: LicensingResponse;
    /**
     * The resolved AWS account ID.
     */
    accountId: string;
}
/**
 * Transforms a Node.js Lambda function to run via the Lambda Kata runtime.
 *
 * This function performs the following steps:
 * 1. Resolves the target AWS account ID
 * 2. Calls the licensing service to validate entitlement
 * 3. If entitled, applies transformations (runtime, handler, layer, env vars)
 * 4. If not entitled, handles according to unlicensedBehavior option
 *
 * @param lambda - The Node.js Lambda function to transform (NodejsFunction or Function)
 * @param props - Optional configuration for the transformation
 * @returns The same Lambda construct (modified if licensed)
 *
 * @example
 * ```typescript
 * import { kata } from '@lambda-kata/cdk';
 * import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
 *
 * const myFunction = new NodejsFunction(this, 'MyFunction', {
 *   entry: 'src/handler.ts',
 * });
 *
 * // Transform to use Lambda Kata runtime
 * kata(myFunction);
 *
 * // With options
 * kata(myFunction, {
 *   unlicensedBehavior: 'fail',
 * });
 * ```
 *
 * @remarks
 * Validates: Requirements 2.1, 3.2
 * - 2.1: WHEN a developer wraps a Node.js Lambda with `kata(lambda)`, THE kata_Wrapper SHALL return a modified Lambda construct
 * - 3.2: THE kata_Wrapper SHALL call the Licensing_Service to validate the account's entitlement
 */
export declare function kata<T extends NodejsFunction | LambdaFunction>(lambda: T, props?: KataWrapperOptions): T;
/**
 * Synchronous version of kata for use when account ID is already known.
 *
 * This is useful for testing or when the account ID can be determined
 * without async operations.
 *
 * @param lambda - The Node.js Lambda function to transform
 * @param accountId - The AWS account ID to use for licensing check
 * @param props - Optional configuration for the transformation
 * @returns Promise resolving to the transformation result
 *
 * @internal
 */
export declare function kataWithAccountId<T extends NodejsFunction | LambdaFunction>(lambda: T, accountId: string, props?: KataWrapperOptions): Promise<KataResult>;
/**
 * Gets the original runtime from a Lambda function before transformation.
 *
 * @param lambda - The Lambda function
 * @returns The original runtime name (e.g., "nodejs20.x")
 *
 * @internal
 */
export declare function getOriginalRuntime(lambda: NodejsFunction | LambdaFunction): string;
/**
 * Detects if a Lambda function uses a Node.js runtime.
 *
 * @param lambda - The Lambda function to check
 * @returns true if the function uses a supported Node.js runtime
 *
 * @internal
 */
export declare function isNodejsRuntime(lambda: NodejsFunction | LambdaFunction): boolean;
/**
 * Gets the architecture of a Lambda function.
 *
 * @param lambda - The Lambda function
 * @returns The architecture ("x86_64" or "arm64")
 *
 * @internal
 */
export declare function getLambdaArchitecture(lambda: NodejsFunction | LambdaFunction): 'x86_64' | 'arm64';
/**
 * Applies the Lambda Kata transformation to a Lambda function.
 *
 * This function modifies the Lambda construct in-place to:
 * 1. Create and attach a config layer with the original handler path
 * 2. Change the runtime to Python 3.12
 * 3. Set the handler to the Lambda Kata handler
 * 4. Attach the customer-specific Lambda Layer
 * 5. Add additional environment variables for the Lambda Kata runtime
 *
 * @param lambda - The Lambda function to transform
 * @param config - The transformation configuration
 *
 * @remarks
 * Validates: Requirements 2.2, 2.3, 2.4, 3.3, 3.4, 4.1, 4.2, 5.4
 * - 2.2: THE kata_Wrapper SHALL change the Lambda runtime from Node.js to Python 3.12
 * - 2.3: THE kata_Wrapper SHALL set the Lambda handler to `lambdakata.optimized_handler.lambda_handler`
 * - 2.4: THE kata_Wrapper SHALL attach the customer-specific Lambda_Layer ARN to the Lambda
 * - 3.3: THE kata_Wrapper SHALL attach the Config_Layer to the transformed Lambda
 * - 3.4: THE kata_Wrapper SHALL NOT set the `JS_HANDLER_PATH` environment variable
 * - 4.1: THE kata_Wrapper SHALL NOT add the `JS_HANDLER_PATH` environment variable to transformed Lambdas
 * - 4.2: WHEN `bundlePath` is specified, THE kata_Wrapper SHALL write it to the Config_Layer JSON as `bundle_path`
 * - 5.4: THE compiled middleware SHALL be included in the Config_Layer at `/opt/.kata/middleware.js`
 *
 * @internal
 */
export declare function applyTransformation(lambda: NodejsFunction | LambdaFunction, config: TransformationConfig): void;
/**
 * Handles the case when an account is not licensed.
 *
 * Depending on the unlicensedBehavior option:
 * - 'warn' (default): Emit a warning and keep the original Lambda unchanged
 * - 'fail': Throw an error to fail CDK synthesis
 *
 * @param lambda - The Lambda function
 * @param props - The kata wrapper options
 * @param licensingResponse - The licensing response
 *
 * @remarks
 * Validates: Requirements 3.5, 3.6, 6.1, 6.2, 6.3, 6.4
 * - 3.5: IF the account is NOT entitled, THEN THE kata_Wrapper SHALL NOT apply any transformations
 * - 3.6: IF the account is NOT entitled, THEN THE kata_Wrapper SHALL emit a clear warning message
 * - 6.1: IF the Licensing_Service returns an unlicensed status, THEN THE kata_Wrapper SHALL keep the original Node.js runtime unchanged
 * - 6.2: IF the Licensing_Service returns an unlicensed status, THEN THE kata_Wrapper SHALL keep the original handler unchanged
 * - 6.3: IF the Licensing_Service returns an unlicensed status, THEN THE kata_Wrapper SHALL NOT attach any Lambda_Layer
 * - 6.4: IF the Licensing_Service returns an unlicensed status, THEN THE kata_Wrapper SHALL emit a warning message
 *
 * @internal
 */
export declare function handleUnlicensed(lambda: NodejsFunction | LambdaFunction, props: KataWrapperOptions | undefined, licensingResponse: LicensingResponse): void;
/**
 * Checks if a Lambda function has been transformed by kata().
 *
 * @param lambda - The Lambda function to check
 * @returns true if the Lambda has been transformed
 *
 * @example
 * ```typescript
 * const myFunction = new NodejsFunction(this, 'MyFunction', { ... });
 * kata(myFunction);
 *
 * if (isKataTransformed(myFunction)) {
 *   console.log('Function is using Lambda Kata runtime');
 * }
 * ```
 */
export declare function isKataTransformed(lambda: NodejsFunction | LambdaFunction): boolean;
/**
 * Gets the kata transformation promise for a Lambda function.
 *
 * This is useful for testing or when you need to await the transformation result.
 *
 * @param lambda - The Lambda function
 * @returns The transformation promise, or undefined if kata() was not called
 *
 * @example
 * ```typescript
 * const myFunction = new NodejsFunction(this, 'MyFunction', { ... });
 * kata(myFunction);
 *
 * const result = await getKataPromise(myFunction);
 * if (result?.transformed) {
 *   console.log(`Transformed with layer: ${result.licensingResponse.layerArn}`);
 * }
 * ```
 */
export declare function getKataPromise(lambda: NodejsFunction | LambdaFunction): Promise<KataResult> | undefined;
