import { Repository } from 'typeorm';
import { NetaClawMemoryEntity } from '../entity/memory.js';
import { MemoryProvider, AgentMemoryConfig } from './provider.js';
import { MysqlMemoryProvider } from './mysql_provider.js';
import { SqliteMemoryProvider } from './sqlite_provider.js';

export function createMemoryProvider(
  config: AgentMemoryConfig,
  mysqlRepo?: Repository<NetaClawMemoryEntity>,
): MemoryProvider {
  if (config.backend === 'sqlite') {
    return new SqliteMemoryProvider(config.sqlitePath);
  }
  if (!mysqlRepo) {
    throw new Error('MysqlMemoryProvider requires a TypeORM repository');
  }
  return new MysqlMemoryProvider(mysqlRepo);
}
