import type { MemoryAdapter, MemoryConfig } from './types.js';

type MemoryType = MemoryConfig['type'];

const registry = new Map<MemoryType, (config: MemoryConfig) => MemoryAdapter>();

export function registerMemoryAdapter(
  type: MemoryType,
  factory: (config: MemoryConfig) => MemoryAdapter,
): void {
  registry.set(type, factory);
}

export function createMemoryAdapter(config: MemoryConfig): MemoryAdapter {
  const factory = registry.get(config.type);
  if (!factory) throw new Error(`No adapter registered for type: ${config.type}`);
  return factory(config);
}
