// AI 플랫폼(LLM Provider) 설정(ADMIN). [GUARDiA-Signage]
//   /api/admin/ai-config (ADMIN 전용) — API 키 값은 응답에 절대 포함되지 않음(claudeKeySet 플래그만).
//   레퍼런스: GUARDiA ESN/OCR AiPlatformSettings — provider 5종(ollama/qwen3/deepseek/glm/claude).
import api from './client'

/** LLM 제공자: ollama/qwen3/deepseek/glm(온프레미스) / claude(외부). */
export type AiProvider = 'ollama' | 'claude' | 'qwen3' | 'deepseek' | 'glm'

/** 화이트리스트 Claude 모델 ID. */
export type ClaudeModel = 'claude-sonnet-4-6' | 'claude-haiku-4-5' | 'claude-opus-4-8'

/** AI 설정 조회 DTO — API 키 값 미반환(claudeKeySet 으로 설정 여부만). */
export interface AiConfigDto {
  provider: AiProvider
  ollamaTextModel: string
  claudeModel: string
  claudeKeySet: boolean
  aiEnabled: boolean
}

export interface AiConfigUpdateRequest {
  provider: AiProvider
  claudeModel?: ClaudeModel
  ollamaTextModel?: string
}

export interface AiTestResult {
  ok: boolean
  degraded: boolean
  message: string
}

export const getAiConfig = () =>
  api.get('/api/admin/ai-config').then(r => r.data?.data as AiConfigDto)

export const updateAiConfig = (body: AiConfigUpdateRequest) =>
  api.put('/api/admin/ai-config', body).then(r => r.data?.data as AiConfigDto)

export const testAiConfig = () =>
  api.post('/api/admin/ai-config/test', {}).then(r => r.data?.data as AiTestResult)
