/**
 * Import adapter registry. Adding an entity = add an adapter file + register
 * it here; the engine and UI are driven entirely off this map.
 *
 * Implemented so far: companies, clients, berths (no-FK). The FK entities
 * (yachts, interests, tenancies, expenses) layer in as their adapters land.
 */
import { berthsAdapter } from './adapters/berths';
import { clientsAdapter } from './adapters/clients';
import { companiesAdapter } from './adapters/companies';
import type { ImportAdapter, ImportEntityKey } from './types';

export const IMPORT_REGISTRY: Partial<Record<ImportEntityKey, ImportAdapter>> = {
  companies: companiesAdapter,
  clients: clientsAdapter,
  berths: berthsAdapter,
};

export function getAdapter(key: string): ImportAdapter | null {
  return IMPORT_REGISTRY[key as ImportEntityKey] ?? null;
}

/** Implemented adapters in dependency order (companies → … → expenses). */
export function listAdapters(): ImportAdapter[] {
  return Object.values(IMPORT_REGISTRY)
    .filter((a): a is ImportAdapter => Boolean(a))
    .sort((a, b) => a.order - b.order);
}
