/**
 * Persistence mode configuration
 * Determines whether the gateway uses in-memory storage or PostgreSQL
 */

export type PersistenceMode = 'memory' | 'postgres';

/**
 * Get the current persistence mode from environment
 * 'memory' -> in-memory storage (no database)
 * 'postgres' or 'persistent' -> PostgreSQL via Prisma
 */
export function getPersistenceMode(): PersistenceMode {
  const mode = process.env['GATEWAY_PERSISTENCE'];
  
  // 'persistent' is an alias for 'postgres' for backward compatibility
  if (mode === 'persistent' || mode === 'postgres') {
    return 'postgres';
  }
  
  // Default to memory if explicitly set, otherwise postgres
  return mode === 'memory' ? 'memory' : 'postgres';
}

/**
 * Check if running in memory mode
 */
export function isMemoryMode(): boolean {
  return getPersistenceMode() === 'memory';
}

/**
 * Check if running in postgres mode
 */
export function isPostgresMode(): boolean {
  return getPersistenceMode() === 'postgres';
}

