import { describe, expect, it } from 'vitest';
import { configSchema } from '../config/schema.js';
import { createConfiguredExternalBackends } from './index.js';

describe('createConfiguredExternalBackends', () => {
  it('returns externalBackends under the routing key expected by createMessageRouter', () => {
    const config = configSchema.parse({
      telegram: { bot_token: 'test-token', allowed_chat_ids: [1] },
      models: { default: { provider: 'anthropic', model: 'claude-3-5-sonnet-latest' } },
      backends: {
        default: 'pi_embedded',
        pi_embedded: {
          enabled: true,
          module: '@mariozechner/pi-agent-core',
        },
      },
    });

    const resolved = createConfiguredExternalBackends(config);

    expect(resolved.defaultName).toBe('pi_embedded');
    expect(resolved.externalBackends.pi_embedded?.name).toBe('pi_embedded');
    expect((resolved as unknown as { backends?: unknown }).backends).toBeUndefined();
  });
});
