/*
 * Runtime Web – Unified Serverless Framework for Full-Stack TypeScript Applications
 * Documentation: https://runtimeweb.com/docs/getting-started
 *
 * @template: ai-chat
 */

/**
 * AI Chat Ties Class
 *
 * Registers AI Chat-related services for dependency injection in Lambda handlers.
 * Uses the object-based ties registration pattern with meaningful property names
 * that match the handler ties definitions.
 *
 * Services registered:
 * - bedrock: AWS Bedrock service for AI model invocations
 * - bedrockStream: AWS Bedrock streaming service for token-by-token responses
 * - memory: DynamoDB-based session memory service
 *
 * @module ties/ai-chat.ties
 */

import type { PureContainer } from '@worktif/utils';
import { BedrockService } from '../backend-services/bedrock.service';
import { BedrockStreamService } from '../backend-services/bedrock-stream.service';
import { MemoryService } from '../backend-services/memory.service';

/**
 * AI Chat Ties Class
 *
 * Registers services for the AI Chat template handlers.
 *
 * @example
 * ```typescript
 * const definition: MicroserviceDefinition = {
 *   ties: [AiChatTies],
 *   lambdas: [chatHandler, healthHandler, streamHandler]
 * };
 * ```
 */
export class AiChatTies {
    /**
     * Object-based registration using meaningful property names as keys.
     * This enables type-safe dependency access via event.ties.
     *
     * Property names here must match the property names in handler ties objects:
     * - bedrock: BedrockService for AI model invocations
     * - bedrockStream: BedrockStreamService for streaming responses
     * - memory: MemoryService for session history storage
     */
    static register = {
        bedrock: {
            instance: BedrockService,
            dependencies: [],
        },
        bedrockStream: {
            instance: BedrockStreamService,
            dependencies: [],
        },
        memory: {
            instance: MemoryService,
            dependencies: [],
        },
    };

    /**
     * Legacy register method for backward compatibility.
     *
     * @deprecated Use static register property for object-based ties
     * @param container - PureContainer instance
     */
    register(container: PureContainer<string>): void {
        container.tie({
            ['bedrock']: {
                instance: BedrockService,
                dependencies: [],
            },
            ['bedrockStream']: {
                instance: BedrockStreamService,
                dependencies: [],
            },
            ['memory']: {
                instance: MemoryService,
                dependencies: [],
            },
        });
    }
}
