import { describe, it, expect } from 'vitest';
import { AgentConfigRegistry, type AgentConfig } from './registry.js';

describe('AgentConfigRegistry', () => {
  describe('register()', () => {
    it('registers a named agent config', () => {
      const registry = new AgentConfigRegistry();
      const config: AgentConfig = { name: 'assistant', systemPrompt: 'Be helpful.' };
      registry.register(config);

      expect(registry.get('assistant')).toEqual(config);
    });

    it('throws on duplicate name', () => {
      const registry = new AgentConfigRegistry();
      registry.register({ name: 'assistant' });
      expect(() => registry.register({ name: 'assistant' })).toThrow('already registered');
    });
  });

  describe('get()', () => {
    it('returns undefined for unknown name', () => {
      const registry = new AgentConfigRegistry();
      expect(registry.get('nonexistent')).toBeUndefined();
    });
  });

  describe('list()', () => {
    it('returns all registered configs', () => {
      const registry = new AgentConfigRegistry();
      registry.register({ name: 'a' });
      registry.register({ name: 'b' });
      expect(registry.list().map(c => c.name).sort()).toEqual(['a', 'b']);
    });
  });

  describe('loadFromConfig()', () => {
    it('loads configs from a raw config object', () => {
      const registry = new AgentConfigRegistry();
      registry.loadFromConfig({
        assistant: {
          system_prompt: 'Be helpful.',
          model_tier: 'default',
          tool_profile: 'messaging',
          sandbox: false,
        },
        coder: {
          model_tier: 'complex',
          tool_profile: 'coding',
          sandbox: true,
        },
      });

      expect(registry.list()).toHaveLength(2);
      const assistant = registry.get('assistant')!;
      expect(assistant.systemPrompt).toBe('Be helpful.');
      expect(assistant.modelTier).toBe('default');
      expect(assistant.toolProfile).toBe('messaging');

      const coder = registry.get('coder')!;
      expect(coder.sandbox).toBe(true);
    });
  });
});
