import { ToolDefinition, ALL_TOOLS } from '../tools';

export interface AgentConfig {
    name: string;
    description: string;
    model: string;      // tier ('A' | 'B' | 'C') or specific model ID
    promptId: string;   // key into the prompt registry (src/prompts/<id>.ts)
    tools: ToolDefinition[];
}

const _registry = new Map<string, AgentConfig>();

export function registerAgent(config: AgentConfig): void {
    _registry.set(config.name, config);
}

export function getAgent(name: string): AgentConfig | undefined {
    return _registry.get(name);
}

export function allAgents(): AgentConfig[] {
    return [..._registry.values()];
}

/**
 * Backwards-compatible AGENTS object — populated as agents register.
 * server.ts uses AGENTS[name] and Object.values(AGENTS).
 */
export const AGENTS: Record<string, AgentConfig> = new Proxy({} as Record<string, AgentConfig>, {
    get(_target, prop: string) { return _registry.get(prop); },
    ownKeys() { return [..._registry.keys()]; },
    getOwnPropertyDescriptor(_target, prop: string) {
        const v = _registry.get(prop);
        return v ? { configurable: true, enumerable: true, value: v } : undefined;
    }
});

/** Pick tools from ALL_TOOLS by name. */
export function pick(names: string[]): ToolDefinition[] {
    return ALL_TOOLS.filter(t => names.includes(t.name));
}
