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

import type { PureContainer } from '@worktif/utils';
import { BedrockService } from '../services/bedrock.service';
import { MemoryService } from '../services/memory.service';
import { SearchService } from '../services/search.service';

/**
 * AI Ties Class
 *
 * Registers AI-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
 * - memory: DynamoDB-based session memory service
 * - search: OpenSearch-based vector similarity search service
 *
 * @example
 * ```typescript
 * const definition: MicroserviceDefinition = {
 *   ties: [AiTies],
 *   lambdas: [chatHandler]
 * };
 * ```
 */
export class AiTies {
    /**
     * 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
     * - memory: MemoryService for session history storage
     * - search: SearchService for vector similarity search
     */
    static register = {
        bedrock: {
            instance: BedrockService,
            dependencies: [],
        },
        memory: {
            instance: MemoryService,
            dependencies: [],
        },
        search: {
            instance: SearchService,
            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: [],
            },
            ['memory']: {
                instance: MemoryService,
                dependencies: [],
            },
            ['search']: {
                instance: SearchService,
                dependencies: [],
            },
        });
    }
}
