const PROVIDERS = [
  {
    id: 'openai',
    name: 'OpenAI',
    baseUrl: 'https://api.openai.com/v1',
    format: 'openai',
    modelsUrl: 'https://api.openai.com/v1/models',
    models: [
      'gpt-4o', 'gpt-4o-mini', 'gpt-4o-2024-05-13', 'gpt-4o-2024-08-06', 'gpt-4o-2024-11-20',
      'gpt-4-turbo', 'gpt-4.1', 'gpt-4.1-mini', 'gpt-4.1-nano',
      'gpt-5', 'gpt-5-mini', 'gpt-5-nano', 'gpt-5-pro', 'gpt-5-codex',
      'gpt-5.1', 'gpt-5.1-codex', 'gpt-5.1-codex-max', 'gpt-5.1-codex-mini',
      'gpt-5.2', 'gpt-5.2-pro', 'gpt-5.2-codex',
      'gpt-5.3-codex', 'gpt-5.3-codex-spark',
      'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-nano', 'gpt-5.4-pro',
      'o1', 'o1-mini', 'o1-preview', 'o1-pro',
      'o3', 'o3-mini', 'o3-pro', 'o3-deep-research',
      'o4-mini', 'o4-mini-deep-research',
      'codex-mini-latest'
    ],
    visionModels: ['gpt-4o', 'gpt-5', 'gpt-5.1', 'gpt-5.2', 'gpt-5.3', 'gpt-5.4'],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'anthropic',
    name: 'Anthropic',
    baseUrl: 'https://api.anthropic.com/v1',
    format: 'anthropic',
    modelsUrl: null,
    models: [
      'claude-3-5-haiku-20241022', 'claude-3-5-haiku-latest',
      'claude-3-5-sonnet-20240620', 'claude-3-5-sonnet-20241022',
      'claude-3-7-sonnet-20250219',
      'claude-3-haiku-20240307', 'claude-3-opus-20240229', 'claude-3-sonnet-20240229',
      'claude-haiku-4-5', 'claude-haiku-4-5-20251001',
      'claude-opus-4-0', 'claude-opus-4-20250514', 'claude-opus-4-1', 'claude-opus-4-1-20250805',
      'claude-opus-4-5', 'claude-opus-4-5-20251101', 'claude-opus-4-6', 'claude-opus-4-7',
      'claude-sonnet-4-0', 'claude-sonnet-4-20250514',
      'claude-sonnet-4-5', 'claude-sonnet-4-5-20250929', 'claude-sonnet-4-6'
    ],
    visionModels: ['claude-sonnet-4-0', 'claude-sonnet-4-5', 'claude-sonnet-4-6', 'claude-opus-4-0', 'claude-opus-4-5'],
    authHeader: 'x-api-key',
    authPrefix: ''
  },
  {
    id: 'zai',
    name: 'Z.AI',
    baseUrl: 'https://api.z.ai/v1',
    format: 'openai',
    modelsUrl: 'https://api.z.ai/v1/models',
    models: [
      'glm-4.5', 'glm-4.5-air', 'glm-4.5-flash', 'glm-4.5v',
      'glm-4.6', 'glm-4.6v',
      'glm-4.7', 'glm-4.7-flash', 'glm-4.7-flashx',
      'glm-5', 'glm-5-turbo', 'glm-5.1', 'glm-5v-turbo'
    ],
    visionModels: ['glm-4.5v', 'glm-4.6v', 'glm-5v-turbo'],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'zai-coding-plan',
    name: 'Z.AI Coding Plan',
    baseUrl: 'https://api.z.ai/api/coding/paas/v4',
    format: 'openai',
    modelsUrl: 'https://api.z.ai/api/coding/paas/v4/models',
    models: [
      'glm-4.5', 'glm-4.5-air', 'glm-4.5-flash', 'glm-4.5v',
      'glm-4.6', 'glm-4.6v',
      'glm-4.7', 'glm-4.7-flash', 'glm-4.7-flashx',
      'glm-5', 'glm-5-turbo', 'glm-5.1', 'glm-5v-turbo'
    ],
    visionModels: ['glm-4.5v', 'glm-4.6v', 'glm-5v-turbo'],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'minimax',
    name: 'MiniMax',
    baseUrl: 'https://api.minimax.chat/v1',
    format: 'openai',
    modelsUrl: null,
    models: [],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'minimax-coding-plan',
    name: 'MiniMax (International)',
    baseUrl: 'https://api.minimax.io/v1',
    format: 'openai',
    modelsUrl: null,
    models: [
      'MiniMax-M2', 'MiniMax-M2.1',
      'MiniMax-M2.5', 'MiniMax-M2.5-highspeed',
      'MiniMax-M2.7', 'MiniMax-M2.7-highspeed'
    ],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'minimax-cn-coding-plan',
    name: 'MiniMax (China)',
    baseUrl: 'https://api.minimaxi.com/v1',
    format: 'openai',
    modelsUrl: null,
    models: [
      'MiniMax-M2', 'MiniMax-M2.1',
      'MiniMax-M2.5', 'MiniMax-M2.5-highspeed',
      'MiniMax-M2.7', 'MiniMax-M2.7-highspeed'
    ],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'google',
    name: 'Google Gemini',
    baseUrl: 'https://generativelanguage.googleapis.com/v1beta',
    format: 'google',
    modelsUrl: null,
    models: [
      'gemini-1.5-pro', 'gemini-1.5-flash',
      'gemini-2.0-flash', 'gemini-2.0-pro',
      'gemini-2.5-pro', 'gemini-2.5-flash'
    ],
    visionModels: ['gemini-1.5-pro', 'gemini-2.0-pro', 'gemini-2.5-pro', 'gemini-2.5-flash'],
    authHeader: 'x-goog-api-key',
    authPrefix: ''
  },
  {
    id: 'github-copilot',
    name: 'GitHub Copilot',
    baseUrl: 'https://api.github.com/copilot',
    format: 'openai',
    modelsUrl: null,
    models: [
      'gpt-4o', 'gpt-4o-mini', 'claude-3.5-sonnet', 'claude-3-opus'
    ],
    visionModels: ['gpt-4o'],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'openrouter',
    name: 'OpenRouter',
    baseUrl: 'https://openrouter.ai/api/v1',
    format: 'openai',
    modelsUrl: 'https://openrouter.ai/api/v1/models',
    models: [],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'mistral',
    name: 'Mistral AI',
    baseUrl: 'https://api.mistral.ai/v1',
    format: 'openai',
    modelsUrl: 'https://api.mistral.ai/v1/models',
    models: [
      'mistral-large-latest', 'mistral-medium-latest',
      'mistral-small-latest', 'mistral-tiny',
      'codestral-latest', 'codestral-2501',
      'mistral-saba-latest', 'pixtral-large-latest'
    ],
    visionModels: ['pixtral-large-latest'],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'deepseek',
    name: 'DeepSeek',
    baseUrl: 'https://api.deepseek.com/v1',
    format: 'openai',
    modelsUrl: 'https://api.deepseek.com/v1/models',
    models: [
      'deepseek-chat', 'deepseek-coder', 'deepseek-reasoner'
    ],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'xai',
    name: 'xAI (Grok)',
    baseUrl: 'https://api.x.ai/v1',
    format: 'openai',
    modelsUrl: 'https://api.x.ai/v1/models',
    models: [
      'grok-3', 'grok-3-mini', 'grok-3-fast',
      'grok-2', 'grok-2-mini',
      'grok-vision-beta'
    ],
    visionModels: ['grok-vision-beta'],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'groq',
    name: 'Groq',
    baseUrl: 'https://api.groq.com/openai/v1',
    format: 'openai',
    modelsUrl: 'https://api.groq.com/openai/v1/models',
    models: [
      'llama-3.3-70b-versatile', 'llama-3.1-8b-instant',
      'llama3-70b-8192', 'llama3-8b-8192',
      'mixtral-8x7b-32768', 'gemma2-9b-it'
    ],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'cohere',
    name: 'Cohere',
    baseUrl: 'https://api.cohere.ai/v2',
    format: 'openai',
    modelsUrl: null,
    models: [
      'command-r-plus', 'command-r', 'command-r-08-2024',
      'command', 'command-light', 'command-nightly'
    ],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'perplexity',
    name: 'Perplexity',
    baseUrl: 'https://api.perplexity.ai',
    format: 'openai',
    modelsUrl: null,
    models: [
      'sonar-pro', 'sonar', 'sonar-reasoning', 'sonar-reasoning-pro'
    ],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'azure',
    name: 'Azure OpenAI',
    baseUrl: '',
    format: 'openai',
    modelsUrl: null,
    models: [
      'gpt-4o', 'gpt-4o-mini', 'gpt-4-turbo',
      'gpt-4.1', 'gpt-4.1-mini', 'gpt-4.1-nano',
      'gpt-5', 'gpt-5-mini', 'gpt-5.1', 'gpt-5.2',
      'o1', 'o3', 'o3-mini', 'o4-mini'
    ],
    visionModels: ['gpt-4o', 'gpt-5', 'gpt-5.1'],
    authHeader: 'api-key',
    authPrefix: '',
    customBaseUrl: true
  },
  {
    id: 'huggingface',
    name: 'HuggingFace',
    baseUrl: 'https://api-inference.huggingface.co/v1',
    format: 'openai',
    modelsUrl: null,
    models: [],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'cerebras',
    name: 'Cerebras',
    baseUrl: 'https://api.cerebras.ai/v1',
    format: 'openai',
    modelsUrl: 'https://api.cerebras.ai/v1/models',
    models: [
      'llama-3.3-70b', 'llama-3.1-8b', 'qwen-2.5-32b'
    ],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  },
  {
    id: 'ollama',
    name: 'Ollama Cloud',
    baseUrl: 'https://api.ollama.com/v1',
    format: 'openai',
    modelsUrl: 'https://api.ollama.com/v1/models',
    models: [],
    visionModels: [],
    authHeader: 'Authorization',
    authPrefix: 'Bearer '
  }
];

function getProviderById(id) {
  return PROVIDERS.find(p => p.id === id);
}

function getProviderModels(providerId) {
  const provider = getProviderById(providerId);
  return provider ? provider.models : [];
}

function getProvidersWithKeys(apiKeys) {
  return PROVIDERS.filter(p => apiKeys[p.id] && apiKeys[p.id].trim() !== '');
}

export { PROVIDERS, getProviderById, getProviderModels, getProvidersWithKeys };
