import type { LLMProvider, ProviderId } from '../types';
import { ollama } from './ollama';
import { claude } from './claude';
import { openai, openaiCompatible } from './openai';
import { gemini } from './gemini';
import { sparkcontrol } from './sparkcontrol';

const ALL: Record<ProviderId, LLMProvider> = {
  claude,
  openai,
  'openai-compatible': openaiCompatible,
  gemini,
  ollama,
  sparkcontrol,
};

export function getProvider(id: string): LLMProvider | null {
  return (ALL as Record<string, LLMProvider | undefined>)[id] ?? null;
}

/**
 * True for providers that take a user-supplied base URL (Ollama, SparkControl,
 * OpenAI-compatible). Configuring these is admin-only — a non-admin pointing
 * the server at an arbitrary URL is the SSRF actor vector. The fixed-URL cloud
 * providers (claude/openai/gemini) stay per-user.
 */
export function isCustomUrlProvider(id: string): boolean {
  return !!getProvider(id)?.requiresBaseUrl;
}

/** Stable list for UI dropdowns. Order matches the Settings select. */
export const PROVIDER_ORDER: ProviderId[] = [
  'claude',
  'openai',
  'openai-compatible',
  'gemini',
  'ollama',
  'sparkcontrol',
];

export const PROVIDERS = ALL;
