import request from '@/utils/request'
import { AI_REQUEST_CONFIG, withAiRequestTimeout } from './aiRequest'

export interface AssistantSource {
    type: string
    title: string
    summary: string
    path: string
    source_id: number
}

export interface AssistantMessage {
    id: number
    session_id: number
    role: 'user' | 'assistant'
    content: string
    sources?: AssistantSource[]
    status?: number
    error_msg?: string
    create_time?: string
    pending?: boolean
}

export interface AssistantSession {
    id: number
    title: string
    last_message: string
    last_answer: string
    message_count: number
    last_active_time: string
    create_time: string
}

export function assistantChat(data: { message: string; client_id: string; session_id?: number }) {
    return request.post(
        withAiRequestTimeout({ url: '/assistant/chat', data }),
        { ...AI_REQUEST_CONFIG, retryCount: 0 }
    )
}

export function assistantSessions(data: { client_id: string }) {
    return request.get({ url: '/assistant/sessions', data })
}

export function assistantMessages(data: { client_id: string; session_id: number }) {
    return request.get({ url: '/assistant/messages', data })
}

export function assistantClear(data: { client_id: string; session_id?: number }) {
    return request.post({ url: '/assistant/clear', data })
}
