import 'server-only';
import type { StorageProvider } from './types';
import { resolveStorageProvider } from './server/provider';

export function getStorageProvider(): StorageProvider {
  return resolveStorageProvider();
}

export function buildOrganizationStorageKey(organizationId: string, segments: string[]) {
  const safeSegments = segments
    .map((segment) =>
      segment
        .trim()
        .replace(/\\/g, '/')
        .replace(/^\/+|\/+$/g, '')
    )
    .filter(Boolean);

  return ['organizations', organizationId, ...safeSegments].join('/');
}
