/**
 * Awilix DI Container Setup
 * Creates a decoupled, reusable dependency injection container
 */

import { type AwilixContainer } from 'awilix';
import type { Browser } from '@stock-bot/browser';
import type { CacheProvider } from '@stock-bot/cache';
import type { Logger } from '@stock-bot/logger';
import type { MongoDBClient } from '@stock-bot/mongodb';
import type { PostgreSQLClient } from '@stock-bot/postgres';
import type { ProxyManager } from '@stock-bot/proxy';
import type { QuestDBClient } from '@stock-bot/questdb';
import type { QueueManager } from '@stock-bot/queue';
import type { IServiceContainer } from '@stock-bot/types';
import type { AppConfig } from './config/schemas';

// Re-export for backward compatibility
export type { AppConfig };

/**
 * Service type definitions for type-safe resolution
 */
export interface ServiceDefinitions {
  // Configuration
  config: AppConfig;
  logger: Logger;

  // Core services
  cache: CacheProvider | null;
  proxyManager: ProxyManager | null;
  browser: Browser;
  queueManager: QueueManager | null;

  // Database clients
  mongoClient: MongoDBClient | null;
  postgresClient: PostgreSQLClient | null;
  questdbClient: QuestDBClient | null;

  // Aggregate service container
  serviceContainer: IServiceContainer;
}

// Export typed container
export type ServiceContainer = AwilixContainer<ServiceDefinitions>;
export type ServiceCradle = ServiceDefinitions;

/**
 * Service-specific options for container creation
 */
export interface ServiceContainerOptions {
  enableQuestDB?: boolean;
  enableMongoDB?: boolean;
  enablePostgres?: boolean;
  enableCache?: boolean;
  enableQueue?: boolean;
  enableBrowser?: boolean;
  enableProxy?: boolean;
}
