/**
 * Edge Path Registry
 *
 * Extensible registry for custom edge path calculators.
 * Built-in calculators are resolved first, then custom ones.
 * Used by the plugin system to allow plugins to add new edge path types.
 */

import type { EdgePathCalculator } from './edge-path-calculators';
import { getEdgePathCalculator as getBuiltInCalculator } from './edge-path-calculators';

const customCalculators = new Map<string, EdgePathCalculator>();

/**
 * Register a custom edge path calculator.
 * Custom calculators take precedence over built-in ones with the same name.
 */
export function registerEdgePathCalculator(name: string, calculator: EdgePathCalculator): void {
	customCalculators.set(name, calculator);
}

/**
 * Unregister a custom edge path calculator.
 */
export function unregisterEdgePathCalculator(name: string): boolean {
	return customCalculators.delete(name);
}

/**
 * Get an edge path calculator by name.
 * Checks custom calculators first, then falls back to built-in ones.
 */
export function resolveEdgePathCalculator(name: string): EdgePathCalculator | undefined {
	return customCalculators.get(name) ?? getBuiltInCalculator(name as any);
}

/**
 * Check if a custom calculator is registered.
 */
export function hasCustomEdgePathCalculator(name: string): boolean {
	return customCalculators.has(name);
}

/**
 * Get all registered custom calculator names.
 */
export function getCustomEdgePathCalculatorNames(): string[] {
	return Array.from(customCalculators.keys());
}

/**
 * Clear all custom calculators. Mainly for testing.
 */
export function clearCustomEdgePathCalculators(): void {
	customCalculators.clear();
}
