export const BUILTIN_PROVIDER_IDS = [
  'openai',
  'next-api-oauth',
  'openrouter',
  'aihubmix',
  'bailian-coding-plan',
  'zhipuai',
  'zhipuai-coding-plan',
  'zai',
  'zai-coding-plan',
  'deepseek',
  'zenmux',
  'moonshot',
  'moonshot-ai',
  'kimi-for-coding',
  'google',
  'anthropic',
  'siliconflow',
  'siliconflow-com',
  'ppinfra',
  'ark-code',
  'ollama',
  'lm-studio',
  'xai',
  'minimax-cn',
  'minimax-cn-coding-plan',
  'minimax',
  'minimax-coding-plan',
] as const

export type BuiltinProviderId = (typeof BUILTIN_PROVIDER_IDS)[number]
export type LegacyCustomProviderId = 'custom'
export type CustomProviderId = `cp_${string}`
export type ProviderId
  = | BuiltinProviderId
    | CustomProviderId
    | LegacyCustomProviderId
export type ProviderAdapter
  = | 'openai'
    | 'openai-responses'
    | 'gemini'
    | 'anthropic'

export interface ProviderModel {
  id: string
  name?: string
  family?: string
  display_name?: string
  type?: 'chat' | string

  attachment?: boolean
  reasoning?: { supported: boolean, default?: boolean }
  tool_call?: boolean
  interleaved?: { field: string }
  temperature?: boolean

  knowledge?: string
  release_date?: string
  last_updated?: string
  vision?: boolean
  modalities?: { input?: string[], output?: string[] }
  open_weights?: boolean
  cost?: {
    input?: number
    output?: number
    cache_read?: number
    cache_write?: number
  }
  limit?: { context?: number, output?: number }
}

export interface ProviderDefinition {
  id: BuiltinProviderId
  name: string
  api?: string
  adapter?: ProviderAdapter
  ccmock?: boolean
  customModels?: boolean
  defaultModelId?: string
  models: ProviderModel[]
}

export interface ProviderConnection {
  apiKey?: string
  baseUrl?: string
  models?: ProviderCustomModel[]
}

export interface ProviderCustomModel {
  id: string
  name?: string
  limit?: { context?: number, output?: number }
  vision?: boolean
  reasoning?: { supported: boolean, default?: boolean }
}

export interface CustomProvider {
  id: CustomProviderId
  name: string
  adapter: ProviderAdapter
  baseUrl?: string
  apiKey?: string
  models: ProviderCustomModel[]
}

export interface ProviderCustomConfig {
  baseUrl?: string
  apiKey?: string
  models: ProviderCustomModel[]
}

export interface ProviderState {
  activeId: string
  activeModelByProvider: Record<string, string>
  connections: Record<string, ProviderConnection>
  customProviders: CustomProvider[]
  custom?: ProviderCustomConfig
}
