// Generic types to avoid circular dependencies
export interface GenericClientConfig {
  [key: string]: any;
}

export interface ConnectionPoolConfig {
  name: string;
  poolSize?: number;
  minConnections?: number;
  maxConnections?: number;
  idleTimeoutMillis?: number;
  connectionTimeoutMillis?: number;
  enableMetrics?: boolean;
}

export interface MongoDBPoolConfig extends ConnectionPoolConfig {
  config: GenericClientConfig;
}

export interface PostgreSQLPoolConfig extends ConnectionPoolConfig {
  config: GenericClientConfig;
}

export interface CachePoolConfig extends ConnectionPoolConfig {
  config: GenericClientConfig;
}

export interface QueuePoolConfig extends ConnectionPoolConfig {
  config: GenericClientConfig;
}

export interface ConnectionFactoryConfig {
  service: string;
  environment: 'development' | 'production' | 'test';
  pools?: {
    mongodb?: Partial<MongoDBPoolConfig>;
    postgres?: Partial<PostgreSQLPoolConfig>;
    cache?: Partial<CachePoolConfig>;
    queue?: Partial<QueuePoolConfig>;
  };
}

export interface ConnectionPool<T> {
  name: string;
  client: T;
  metrics: PoolMetrics;
  health(): Promise<boolean>;
  dispose(): Promise<void>;
}

export interface PoolMetrics {
  created: Date;
  totalConnections: number;
  activeConnections: number;
  idleConnections: number;
  waitingRequests: number;
  errors: number;
}

export interface ConnectionFactory {
  createMongoDB(config: MongoDBPoolConfig): Promise<ConnectionPool<any>>;
  createPostgreSQL(config: PostgreSQLPoolConfig): Promise<ConnectionPool<any>>;
  createCache(config: CachePoolConfig): Promise<ConnectionPool<any>>;
  createQueue(config: QueuePoolConfig): Promise<ConnectionPool<any>>;
  getPool(
    type: 'mongodb' | 'postgres' | 'cache' | 'queue',
    name: string
  ): ConnectionPool<any> | undefined;
  listPools(): Array<{ type: string; name: string; metrics: PoolMetrics }>;
  disposeAll(): Promise<void>;
}
