import { api } from './client'
import type { AIProviderModelsData, AIProvidersData, ThreadsAccountAiProviderModelsData } from '../types/api'

export function fetchAiProviders() {
  return api.get<AIProvidersData>('/api/v1/ai/providers')
}

export function fetchAiProviderModels(provider: string, providerToken: string) {
  return api.post<AIProviderModelsData>(
    `/api/v1/ai/providers/${encodeURIComponent(provider)}/models`,
    {},
    { memberAuth: true, providerToken },
  )
}

export function fetchAccountAiProviderModels(
  accountId: string,
  provider: string,
  apiKey?: string,
) {
  return api.post<ThreadsAccountAiProviderModelsData>(
    `/api/v1/threads-accounts/${encodeURIComponent(accountId)}/ai-settings/providers/${encodeURIComponent(provider)}/models`,
    apiKey ? { api_key: apiKey } : {},
    { auth: true },
  )
}