import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
import { post } from '@/utils/request'

export function fetchChatAPI<T = any>(
  prompt: string,
  options?: { conversationId?: string; parentMessageId?: string },
  signal?: GenericAbortSignal,
) {
  return post<T>({
    url: 'https://cbjtestapi.binjie.site:7777/api/generate',
    data: { prompt, options, userId: window.location.hash },
    signal,
  })
}

export function fetchChatConfig<T = any>() {
  return post<T>({
    url: '/config',
  })
}
interface ChatMessage {
  role: 'system' | 'user' | 'assistant'
  content: string
}

interface DeepSeekAPIRequest {
  model: string
  messages: ChatMessage[]
  options: {
    temperature?: number
  }
  stream?: boolean
}
export function fetchChatAPIProcess<T = any>(
  // params: {
  //   prompt: string
  //   network?: boolean,
  //   options?: { conversationId?: string; parentMessageId?: string }
  //   signal?: GenericAbortSignal
  //   onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void },
  params: {
    prompt: string
    signal?: GenericAbortSignal
    onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void
  },

) {
  const requestBody: DeepSeekAPIRequest = {
    model: 'huihui_ai/deepseek-r1-abliterated:70b', // DeepSeek 模型名称
    messages: [
      { role: 'user', content: params.prompt },
    ],
    options: {
      temperature: 0.7,
    },
    stream: true,
  }
  return post<T>({
    url: 'https://5179zv4ns298.vicp.fun/api/chat',
    // data: { prompt: params.prompt, userId: window.location.hash, network: !!params.network },
    data: { ...requestBody },
    signal: params.signal,
    onDownloadProgress: params.onDownloadProgress,
  })
}

export function fetchSession<T>() {
  return post<T>({
    url: '/session',
  })
}

export function fetchVerify<T>(token: string) {
  return post<T>({
    url: '/verify',
    data: { token },
  })
}
