import request from '@/utils/request'

export interface EmbeddingProviderInfo {
  name: string
  display_name: string
  description?: string
  config_schema: Record<string, any>
}

export interface EmbeddingConfig {
  provider: string
  config: Record<string, any>
  updated_at?: string
}

export interface EmbeddingConfigUpdate {
  provider: string
  config?: Record<string, any>
}

export interface EmbeddingTestResult {
  success: boolean
  dimension: number
  latency_ms?: number
  message?: string
  error?: string
}

export interface EmbeddingTestRequest {
  test_text?: string
  config?: EmbeddingConfigUpdate
}

export interface DocumentFormat {
  extension: string
  name: string
  description?: string
}

export interface EmbeddingProvidersResponse {
  providers: EmbeddingProviderInfo[]
}

export interface EmbeddingConfigUpdateResponse {
  success: boolean
  message: string
}

export interface SupportedFormatsResponse {
  formats: DocumentFormat[]
}

export function getProviders() {
  return request({
    url: '/embedding/providers',
    method: 'get'
  })
}

export function getConfig() {
  return request({
    url: '/embedding/config',
    method: 'get'
  })
}

export function saveConfig(data: EmbeddingConfigUpdate) {
  return request({
    url: '/embedding/config',
    method: 'put',
    data
  })
}

export function testEmbedding(data: EmbeddingTestRequest): Promise<EmbeddingTestResult> {
  return request({
    url: '/embedding/test',
    method: 'post',
    data
  })
}

export function getSupportedFormats() {
  return request({
    url: '/embedding/formats',
    method: 'get'
  })
}
