import * as claude from './ai-claude.mjs';
import * as openai from './ai-openai.mjs';
import * as openrouter from './ai-openrouter.mjs';
import * as local from './ai-local.mjs';

const providers = { claude, openai, openrouter, local };

export async function generate(provider, images, systemPrompt, model) {
  const ai = providers[provider];
  if (!ai) throw new Error(`Unknown AI provider: ${provider}`);
  return ai.generate(images, systemPrompt, model);
}

export async function generateText(provider, systemPrompt, userPrompt, model) {
  const ai = providers[provider];
  if (!ai) throw new Error(`Unknown AI provider: ${provider}`);
  if (typeof ai.generateText !== 'function') throw new Error(`Textgenerierung wird von ${provider} nicht unterstützt.`);
  return ai.generateText(systemPrompt, userPrompt, model);
}

export function getProviders() {
  return [
    { id: 'claude', name: 'Claude', hasModels: false, needsKey: 'ANTHROPIC_API_KEY' },
    { id: 'openai', name: 'OpenAI', hasModels: false, needsKey: 'OPENAI_API_KEY' },
    {
      id: 'openrouter',
      name: 'OpenRouter',
      hasModels: true,
      models: openrouter.MODELS,
      needsKey: 'OPENROUTER_API_KEY',
    },
    {
      id: 'local',
      name: 'Lokal (Ollama)',
      hasModels: true,
      models: local.MODELS,
      needsKey: null,
    },
  ];
}
