import * as React from 'react';
import { RouteObject } from 'react-router';
import type { InfraOptions } from './infra.types';
import type { MicroserviceDefinition } from './microservice.types';
import { RuntimeRouterDefaults } from '../../runtime-core';
/**
 * RuntimeRouter interface for runtime-web integration.
 *
 * Defines the essential methods needed by the runtime-web pipelines.
 * This interface matches the actual RuntimeRouter class from @lib/runtime-core/runtime.router.
 */
interface RuntimeRouterInterface {
    /**
     * Get all route objects as an array.
     * Used for creating browser routers and serverless rendering static handlers.
     */
    getRoutes(): Array<RouteObject>;
    /**
     * Find a route by its ID.
     */
    getRouteById?(id: string): RouteObject | undefined;
    /**
     * Find a route by its path.
     */
    getRouteByPath?(path: string): RouteObject | undefined;
    /**
     * Get the routes array (getter).
     */
    routes?: Array<RouteObject>;
    /**
     * Get the default configuration.
     */
    defaults?: RuntimeRouterDefaults;
}
/**
 * Stage environment for deployment.
 *
 * - `dev`: Development environment
 * - `staging`: Staging/pre-production environment
 * - `prod`: Production environment
 */
export type Stage = 'dev' | 'staging' | 'prod';
/**
 * Utility type to extract service names from register configuration.
 *
 * This enables compile-time validation of service names and provides
 * type-safe access to service identifiers throughout the framework.
 *
 * @template T - The register configuration object type
 */
export type ServiceNames<T extends Record<string, MicroserviceDefinition>> = keyof T;
/**
 * Utility type to generate Lambda IDs from service configuration.
 *
 * Combines service names with Lambda IDs to create fully qualified
 * Lambda identifiers for type-safe Lambda resolution.
 *
 * @template T - The register configuration object type
 */
export type LambdaIds<T extends Record<string, MicroserviceDefinition>> = {
    [K in keyof T]: T[K]['lambdas'][number] extends {
        id: infer I;
    } ? I extends string ? `${K & string}.${I}` : never : never;
}[keyof T];
/**
 * Type constraint for valid service names.
 *
 * Ensures service names follow the validation pattern:
 * - Must start with a letter (a-z, A-Z)
 * - Can contain letters, numbers, and hyphens
 * - Maximum length: 128 characters
 *
 * This is a branded type that provides compile-time validation.
 */
export type ValidServiceName = string & {
    readonly __brand: 'ValidServiceName';
};
/**
 * Type guard to validate service name format.
 *
 * @param serviceName - The service name to validate
 * @returns Type predicate indicating if the service name is valid
 */
export declare function isValidServiceName(serviceName: string): serviceName is ValidServiceName;
/**
 * Main configuration interface for Runtime Web Core.
 *
 * This interface provides a unified configuration that works across all execution contexts:
 * - Browser: Hydrates React application with client-side routing
 * - Lambda: Executes server-side rendering and business logic
 * - CDK: Synthesizes CloudFormation infrastructure
 *
 * @template TRegister - The register configuration type for type-safe service names
 *
 * @example
 * ```typescript
 * import { runtime } from '@worktif/runtime/runtime-web';
 * import { RuntimeRouter } from '@worktif/runtime';
 *
 * const config = {
 *   app: ({ router }) => <App router={router} />,
 *   router: new RuntimeRouter({ router: routes, defaults: {} }),
 *   serviceName: 'my-app',
 *   stage: 'dev',
 *   register: {
 *     payments: {
 *       ties: [PaymentsTies],
 *       lambdas: [chargeHandler, refundHandler]
 *     },
 *     users: {
 *       ties: [UsersTies],
 *       lambdas: [createUserHandler, getUserHandler]
 *     }
 *   } as const,  // Use 'as const' for better type inference
 *   infra: {
 *     env: { account: '123456789012', region: 'us-east-1' },
 *     stage: 'dev',
 *     reactEntry: './src/index.tsx',
 *     apiMode: 'apiGateway'
 *   }
 * } satisfies RuntimeWebConfig;
 *
 * runtime(config);
 * ```
 *
 * @todo: after RuntimeWeb repo will be resolved, RuntimeWebConfig MUST extend RuntimeWebConfig Core
 */
export interface RuntimeWebConfig<TRegister extends Record<string, MicroserviceDefinition> = Record<string, MicroserviceDefinition>> {
    /**
     * React application component factory function.
     *
     * Receives the router instance as a dependency and returns the root React element.
     * This pattern enables dependency injection of the router into your application.
     *
     * @param deps - Dependencies object containing the router
     * @param deps.router - RuntimeRouter instance for navigation and routing
     * @returns Root React element (React.ReactElement)
     *
     * @example
     * ```typescript
     * app: ({ router }) => <App router={router} />
     * ```
     */
    app: (deps: {
        router: RuntimeRouterInterface;
    }) => React.ReactElement;
    /**
     * RuntimeRouter instance for application routing.
     *
     * Defines all routes, loaders, and navigation configuration.
     * The router is used in both server-side rendering (Lambda) and client-side hydration (browser).
     *
     * @see {@link RuntimeRouterInterface} for router configuration
     *
     * @example
     * ```typescript
     * router: new RuntimeRouter({
     *   router: [
     *     { path: '/', element: <Home /> },
     *     { path: '/about', element: <About /> }
     *   ],
     *   defaults: {}
     * })
     * ```
     */
    router: RuntimeRouterInterface;
    /**
     * Service name identifier for the application.
     *
     * Used as a prefix for all AWS resources (Lambda functions, API Gateway, S3 buckets, etc.).
     * Must be unique within your AWS account and region.
     *
     * **Validation Rules**:
     * - Must start with a letter (a-z, A-Z)
     * - Can contain letters, numbers, and hyphens
     * - Maximum length: 128 characters
     * - Pattern: `/^[a-zA-Z][a-zA-Z0-9-]{0,127}$/`
     *
     * **Examples**:
     * - Valid: `my-app`, `MyApp`, `app123`, `my-app-v2`
     * - Invalid: `123app` (starts with number), `my_app` (underscore), `my app` (space)
     *
     * @example
     * ```typescript
     * serviceName: 'my-application'
     * ```
     */
    serviceName: string;
    /**
     * Deployment stage/environment.
     *
     * Determines the environment-specific configuration and resource naming.
     * Used to create separate infrastructure stacks for different environments.
     *
     * **Values**:
     * - `dev`: Development environment (local testing, rapid iteration)
     * - `staging`: Staging/pre-production environment (QA, integration testing)
     * - `prod`: Production environment (live users)
     *
     * **Impact**:
     * - Resource naming: `{serviceName}-{resource}-{stage}`
     * - Environment variables: Different configs per stage
     * - Cache TTL: Shorter in dev, longer in prod
     * - Logging: More verbose in dev, structured in prod
     *
     * @example
     * ```typescript
     * stage: 'dev'
     * ```
     */
    stage: Stage;
    /**
     * Microservice registry (runtime-level configuration).
     *
     * **Required**: Defines all microservices, their DI containers, and Lambda endpoints.
     * **Used in all contexts**: Browser (for type generation), Lambda (for DI), CDK (for infrastructure).
     * **Architecture**: This is runtime configuration, separate from infrastructure concerns.
     *
     * Each microservice gets its own PureContainer instance built from the Ties classes.
     * Lambda functions are automatically created and wired with dependency injection.
     *
     * **Type Safety**: Service names are derived from object keys, ensuring compile-time validation.
     * **No Magic Strings**: All service identifiers are type-safe and auto-generated.
     *
     * @see {@link MicroserviceDefinition} for microservice structure
     *
     * @example
     * ```typescript
     * register: {
     *   payments: {
     *     ties: [PaymentsTies, BillingTies],
     *     lambdas: [chargeHandler, refundHandler, webhookHandler]
     *   },
     *   users: {
     *     ties: [UsersTies, AuthTies],
     *     lambdas: [createUserHandler, getUserHandler, loginHandler]
     *   }
     * } as const  // Use 'as const' for better type inference
     * ```
     */
    register: TRegister;
    /**
     * Infrastructure configuration for CDK deployment.
     *
     * **Optional**: Only required when running in CDK context (synthesizing CloudFormation templates).
     * **Not used**: In browser and Lambda contexts (runtime configuration is in register).
     * **Pure infrastructure**: Contains only AWS resource configuration, no business logic.
     *
     * Defines:
     * - AWS account and region
     * - Lambda configuration (memory, timeout, VPC)
     * - API Gateway or Lambda URL mode
     * - Custom domain configuration
     * - React entry point for serverless rendering Lambda
     *
     * @see {@link InfraOptions} for detailed configuration options
     *
     * @example
     * ```typescript
     * infra: {
     *   env: { account: '123456789012', region: 'us-east-1' },
     *   stage: 'dev',
     *   reactEntry: './src/index.tsx',
     *   apiMode: 'apiGateway',
     *   lambdaMemorySize: 1024,
     *   lambdaTimeout: 30,
     *   domain: {
     *     rootDomain: 'myapp.com',
     *     subdomain: 'api'
     *   }
     * }
     * ```
     */
    infra?: InfraOptions;
}
/**
 * Type-safe Runtime configuration with inferred service names.
 *
 * This type provides enhanced type safety by inferring service names from the register
 * configuration, enabling compile-time validation of service references.
 *
 * @template TRegister - The register configuration type
 */
export type TypeSafeRuntimeWebConfig<TRegister extends Record<string, MicroserviceDefinition>> = RuntimeWebConfig<TRegister> & {
    /**
     * Type-safe service names derived from register keys.
     * Available at compile-time for type checking and IDE autocomplete.
     */
    readonly serviceNames?: ServiceNames<TRegister>;
    /**
     * Type-safe Lambda IDs derived from register configuration.
     * Available at compile-time for type checking and IDE autocomplete.
     */
    readonly lambdaIds?: LambdaIds<TRegister>;
};
export {};
