import type { LambdaDefinition, InitFunction } from './lambda.types';
/**
 * Type for Ties class constructors.
 *
 * Ties classes implement the register(container) pattern for dependency injection.
 * They use PureContainer from @worktif/utils to register services.
 *
 * @template T - The type of the Ties class instance
 */
export type TiesInstance<T = unknown> = new (...args: unknown[]) => T;
/**
 * Microservice definition containing DI configuration and Lambda endpoints.
 *
 * A microservice is a logical grouping of related Lambda functions that share
 * a common PureContainer instance for dependency injection.
 *
 * ## Cold Start Initialization
 *
 * Microservices can define an optional `init` function that executes during
 * cold start for all Lambda functions in the microservice. The snapshot from
 * this init function is available to all Lambda handlers via `event.snapshot`.
 *
 * When both microservice-level and lambda-level init exist:
 * 1. Microservice init executes first
 * 2. Lambda init executes second
 * 3. Snapshots are merged with lambda-level taking precedence
 *
 * @template TSnapshot - Snapshot type from microservice init function (defaults to empty object)
 *
 * @example Basic Usage
 * ```typescript
 * const paymentsService: MicroserviceDefinition = {
 *   ties: [PaymentsTies, BillingTies],
 *   lambdas: [chargeHandler, refundHandler, webhookHandler]
 * };
 * ```
 *
 * @example With Init Function
 * ```typescript
 * type SharedSnapshot = { config: AppConfig; dbPool: ConnectionPool };
 *
 * const paymentsService: MicroserviceDefinition<SharedSnapshot> = {
 *   ties: [PaymentsTies, BillingTies],
 *   init: async (ties) => {
 *     const config = await ties.configService.loadConfig();
 *     const dbPool = await ties.dbService.createPool();
 *     return { config, dbPool };
 *   },
 *   lambdas: [chargeHandler, refundHandler, webhookHandler]
 * };
 * ```
 */
export interface MicroserviceDefinition<TSnapshot = {}> {
    /**
     * Array of Ties class constructors for dependency injection.
     *
     * Each Ties class must implement a register(container: PureContainer<string>) method
     * that registers services using container.tie(), container.tieConst(), or container.tieSingleton().
     *
     * The framework automatically creates a PureContainer instance for each microservice
     * and calls register() on each Ties class to build the DI container.
     *
     * @example
     * ```typescript
     * ties: [PaymentsTies, BillingTies, ConfigTies]
     * ```
     */
    ties: TiesInstance[];
    /**
     * Optional initialization function executed during cold start.
     *
     * Init functions run once per Lambda execution environment (cold start only),
     * before the first handler invocation. The returned snapshot is cached and
     * available to all Lambda handlers in this microservice via `event.snapshot`.
     *
     * ## Execution Timing
     *
     * - Executes exactly once per execution environment (cold start)
     * - Executes before any lambda-level init functions
     * - Result is cached for all warm invocations
     * - Snapshot is shared across all Lambda functions in the microservice
     *
     * ## Use Cases
     *
     * - Shared database connection pool
     * - Common configuration loading
     * - Shared SDK client initialization
     * - Cross-lambda cache priming
     *
     * @example
     * ```typescript
     * init: async (ties) => {
     *   const config = await ties.configService.loadConfig();
     *   const dbPool = await ties.dbService.createPool();
     *   return { config, dbPool };
     * }
     * ```
     *
     * @see {@link InitFunction} - The init function type definition
     */
    init?: InitFunction<Record<string, unknown>, TSnapshot>;
    /**
     * Array of Lambda endpoint definitions.
     *
     * Each Lambda definition describes a single Lambda function with its dependencies,
     * handler logic, and optional HTTP integration.
     *
     * The framework automatically creates Lambda functions from these definitions
     * and injects dependencies from the microservice's PureContainer.
     *
     * @example
     * ```typescript
     * lambdas: [
     *   {
     *     id: 'charge',
     *     ties: [PaymentsService, BillingService],
     *     handler: (ties) => async (event, context) => {
     *       return await ties.paymentsService.processCharge(event.body);
     *     },
     *     http: {
     *       method: 'POST',
     *       path: '/api/payments/charge',
     *       auth: 'jwt'
     *     }
     *   }
     * ]
     * ```
     */
    lambdas: Array<LambdaDefinition<any, any>>;
}
/**
 * Enhanced microservice definition supporting both array and object-based lambda definitions.
 *
 * @deprecated Use MicroserviceDefinition which now supports both patterns
 */
export type EnhancedMicroserviceDefinition<TSnapshot = {}> = MicroserviceDefinition<TSnapshot>;
